Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Threading race condition bugfix for optimize_snr in pycbc_live #4342

Merged
merged 6 commits into from
Aug 8, 2023

Conversation

xangma
Copy link
Contributor

@xangma xangma commented Apr 27, 2023

Problem:
There was a potential race condition in bin/pycbc_live where:

  • if a coinc or single occurs,
  • optimize_snr_checks == True,
  • and the thread starts the optimize snr subprocess,

the main thread could have moved the analysis chunk on before the setup_optimize_snr function re-reads some data from self - the event class instance,. This causes lines like this: curr_data = self.data_readers[ifo].overwhitened_data(delta_f) to potentially read the wrong data.

Solution:
Split the setup_optimize_snr function, which normally accesses/modifies data in event, into two functions: setup_optimize_snr and run_optimize_snr. The setup function reads and saves all the data in the main thread before any GraceDB uploads or optimizing ensuring the correct data is saved before the main thread moves the analysis on. It returns the command to be run as a subprocess and the output directory. The run function takes these as inputs and runs after the event is uploaded.
One extra modification I had to include is because the setup_optimize_snr function was dependent on the gid from GraceDB, the run_optimize_snr function has to re-open and close the attributes hdf to add the gid in.

Happy for any suggestions/modifications. This is the best idea I've had since I found this was happening.

bin/pycbc_live Outdated Show resolved Hide resolved
@xangma xangma force-pushed the race_condition_bugfix branch 4 times, most recently from 8deb002 to 4991669 Compare April 27, 2023 15:57
@xangma
Copy link
Contributor Author

xangma commented Apr 27, 2023

Is there any appetite for putting a comment in upload_in_thread stating something like this? :

#Warning: there be dragons ahead. Within threads created by the main thread, race conditions must be considered when accessing any data from unlocked objects that the main thread could be changing - e.g self.data_readers.

bin/pycbc_live Outdated Show resolved Hide resolved
bin/pycbc_live Outdated Show resolved Hide resolved
@tdent
Copy link
Contributor

tdent commented May 23, 2023

Seems like we could now use the MDC to test this, at least for a short time, given that it served its pre-O4 review purpose.

@GarethCabournDavies
Copy link
Contributor

Note that as Xan is away at the moment, I will be working on this as well, so can no longer review!

@titodalcanton
Copy link
Contributor

I plan to finally look into this next week.

@GarethCabournDavies
Copy link
Contributor

Poke on this

@GarethCabournDavies GarethCabournDavies self-assigned this Jul 4, 2023
@GarethCabournDavies
Copy link
Contributor

Poke on this - this would be good to get in soon(ish)

@GarethCabournDavies
Copy link
Contributor

@titodalcanton - is this in the pycbc live testing environment at the moment?

@titodalcanton
Copy link
Contributor

No, only stuff on master is being tested on the MDC. This is now (again) near the top of my priority list.

bin/pycbc_live Outdated Show resolved Hide resolved
bin/pycbc_live Outdated
Comment on lines 111 to 113
# Give this a nominal value, it is requried but not used
self.fu_cores = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: requried -> required. Also, there should probably be a if self.fu_cores is not None condition down below in setup_optimize_snr where fu_cores is used, otherwise I do not think the resulting command (--cores None) would be valid.

@titodalcanton titodalcanton enabled auto-merge (squash) August 8, 2023 13:44
Copy link
Contributor

@titodalcanton titodalcanton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no more comments, let's merge this and get it running on the MDC.

@titodalcanton titodalcanton merged commit bfff82b into gwastro:master Aug 8, 2023
36 checks passed
PRAVEEN-mnl pushed a commit to PRAVEEN-mnl/pycbc that referenced this pull request Nov 3, 2023
…ro#4342)

* setup snr_opt before threading

* Some minor tweaks, setup optimize_snr even if not performing it

* Dont open file unless using it

* TDC comments

* clarify comments

* bug

---------

Co-authored-by: GarethCabournDavies <[email protected]>
titodalcanton pushed a commit to titodalcanton/pycbc that referenced this pull request Jan 16, 2024
…ro#4342)

* setup snr_opt before threading

* Some minor tweaks, setup optimize_snr even if not performing it

* Dont open file unless using it

* TDC comments

* clarify comments

* bug

---------

Co-authored-by: GarethCabournDavies <[email protected]>
bhooshan-gadre pushed a commit to bhooshan-gadre/pycbc that referenced this pull request Mar 4, 2024
…ro#4342)

* setup snr_opt before threading

* Some minor tweaks, setup optimize_snr even if not performing it

* Dont open file unless using it

* TDC comments

* clarify comments

* bug

---------

Co-authored-by: GarethCabournDavies <[email protected]>
acorreia61201 pushed a commit to acorreia61201/pycbc that referenced this pull request Apr 4, 2024
…ro#4342)

* setup snr_opt before threading

* Some minor tweaks, setup optimize_snr even if not performing it

* Dont open file unless using it

* TDC comments

* clarify comments

* bug

---------

Co-authored-by: GarethCabournDavies <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants