-
Notifications
You must be signed in to change notification settings - Fork 106
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
Race condition between core->flush() and startup of feeding thread for asynchronous sink #131
Comments
Thanks for the report. At the moment you could work around it by running the internal feeding thread in the sink frontend (by not setting |
Thanks. Does allowing the constructor to start the thread eliminate the race (perhaps by recording the feeding thread ID prior to returning) or does it merely shrink the window in which the race might occur? I'm assuming the constructor does not wait to return until the thread is actually running... |
The constructor doesn't wait, but instead |
Ah, I see. Just read the code for start_feeding_thread and flush and I see the difference between the implicit start and providing my own feeding thread. Will see if we can leverage this in the mean time. |
There's a race condition between the core->flush() operation and the startup of the feeding thread for asynchronous sinks that can result in the program aborting with an unhandled exception from the feeding thread. It is possible for core->flush() to begin doing the work of feeding records through an asynchronous sink before the sink's feeding thread has a chance to fully enter the running state. This results in an exception from asynchronous_sink::run() when the feeding thread discovers that there is already another thread (the thread calling flush()) servicing the sink.
The attached reproduction example makes this race more reliable by inserting a slight delay into the background feeding thread. In out application, however, there is no such artificial delay and the race condition is exposed simply by system load and differing scheduling of the thread calling flush() and the background feeding thread in an asynchronous sink.
Here's the call stack where the exception is thrown when the background feeding thread tries to start:
And here's the program main thread, which is already deep inside the flush operation:
And here's the code for the reproduction:
The text was updated successfully, but these errors were encountered: