-
Notifications
You must be signed in to change notification settings - Fork 50
feat: all executors now create daemon threads to reduce shutdown time #1715
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ class EventSupport { | |
| private final Map<String, HandlerStore> handlerStores = new ConcurrentHashMap<>(); | ||
| private final HandlerStore globalHandlerStore = new HandlerStore(); | ||
| private final ExecutorService taskExecutor = | ||
| Executors.newCachedThreadPool(new ConfigurableThreadFactory("openfeature-event-handler-thread")); | ||
| Executors.newCachedThreadPool(new ConfigurableThreadFactory("openfeature-event-handler-thread", true)); | ||
|
Comment on lines
30
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to my comment on If these handlers perform operations that require cleanup in It would be safer to use non-daemon threads to ensure that handlers can complete their work, or at least their cleanup routines, during a graceful shutdown. This would enforce correct lifecycle management by the user of the SDK. |
||
|
|
||
| /** | ||
| * Run all the event handlers associated with this domain. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the threads to daemon threads introduces a risk. Daemon threads can be abruptly terminated by the JVM on shutdown, which does not guarantee the execution of
finallyblocks.In the task submitted to
emitterExecutor(lines 93-104), there is afinallyblock that callsawaitable.wakeup()and atry-with-resourcesstatement that releases a read lock. If this thread is terminated abruptly, theAwaitablemight never be woken up, and the lock might not be released.While the
shutdown()method attempts a graceful shutdown, using daemon threads can hide lifecycle management issues whereshutdown()is not called. Given the critical operations within thefinallyblock, it might be safer to use non-daemon threads to ensure cleanup logic is always executed, forcing the SDK user to manage the provider lifecycle correctly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we care about a lock not getting released when the JVM is terminated