Deadlock on Provider init #1299
Labels
bug
Something isn't working
good first issue
Good for newcomers
help wanted
Extra attention is needed
In my newest PR, which replaces a busy wait with a wait/notify construct, I discovered that one can run into a deadlock when emitting events during the initialization.
In more detail, the thread that initializes a
FlagdProvider
starts the initialization of theflagResolver
, and then waits for an event announcing that the provider is ready.When this ready event is received in the
FlagdProvider
, it callsEventProvider#emitProviderReady(…)
, which then deadlocks.Steps to Reproduce
I wrote a very basic provider, which always deadlocks on initialization. It can be found here.
I made my original discovery in this PR. It can be triggered by running the e2e tests. Notice that the test will keep printing
to the console. The warning of the invalid flag config can be ignored, this is expected in the test. The warning
Failed to convey OK satus, queue is full
, however, is an indicator of the problem, as the thread that is supposed to drain this queue is deadlocked.Expected Behavior
The
EventProvider
should never deadlock, no matter under which conditions theemit
(oremitProviderReady
) method is called. When I wrap the call to theemitProviderReady()
method inside theonReady()
method in theFlagdProvider
in a new thread, the deadlock is prevented.Possible Fix
EventProvider#emit(…)
should not directly callthis.onEmit.accept(this, event, details);
, instead it should store the call in some thread safe queue, which is drained by another thread.The text was updated successfully, but these errors were encountered: