Skip to content

Commit 306b74f

Browse files
committed
Flaky build due to a possible race condition #1449
Signed-off-by: christian.lutnik <[email protected]>
1 parent 40b319c commit 306b74f

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/main/java/dev/openfeature/sdk/EventProvider.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,21 @@ public void shutdown() {
7676
* @param event The event type
7777
* @param details The details of the event
7878
*/
79-
public void emit(ProviderEvent event, ProviderEventDetails details) {
80-
if (eventProviderListener != null) {
81-
eventProviderListener.onEmit(event, details);
79+
public void emit(final ProviderEvent event, final ProviderEventDetails details) {
80+
final var localEventProviderListener = this.eventProviderListener;
81+
final var localOnEmit = this.onEmit;
82+
83+
if (localEventProviderListener == null && localOnEmit == null) {
84+
return;
8285
}
8386

84-
final TriConsumer<EventProvider, ProviderEvent, ProviderEventDetails> localOnEmit = this.onEmit;
85-
if (localOnEmit != null) {
86-
emitterExecutor.submit(() -> localOnEmit.accept(this, event, details));
87+
try (var ignored = OpenFeatureAPI.lock.readLockAutoCloseable()) {
88+
if (localEventProviderListener != null) {
89+
localEventProviderListener.onEmit(event, details);
90+
}
91+
if (localOnEmit != null) {
92+
localOnEmit.accept(this, event, details);
93+
}
8794
}
8895
}
8996

src/test/java/dev/openfeature/sdk/EventsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class EventsTest {
2424
private OpenFeatureAPI api;
2525

2626
@BeforeEach
27-
public void setUp() throws Exception {
27+
void setUp() {
2828
api = new OpenFeatureAPI();
2929
}
3030

@@ -578,7 +578,7 @@ void shouldHaveAllProperties() {
578578
number = "5.3.3",
579579
text = "Handlers attached after the provider is already in the associated state, MUST run immediately.")
580580
void matchingReadyEventsMustRunImmediately() {
581-
final String name = "matchingEventsMustRunImmediately";
581+
final String name = "matchingReadyEventsMustRunImmediately";
582582
final Consumer<EventDetails> handler = mockHandler();
583583

584584
// provider which is already ready
@@ -597,7 +597,7 @@ void matchingReadyEventsMustRunImmediately() {
597597
number = "5.3.3",
598598
text = "Handlers attached after the provider is already in the associated state, MUST run immediately.")
599599
void matchingStaleEventsMustRunImmediately() {
600-
final String name = "matchingEventsMustRunImmediately";
600+
final String name = "matchingStaleEventsMustRunImmediately";
601601
final Consumer<EventDetails> handler = mockHandler();
602602

603603
// provider which is already stale
@@ -618,7 +618,7 @@ void matchingStaleEventsMustRunImmediately() {
618618
number = "5.3.3",
619619
text = "Handlers attached after the provider is already in the associated state, MUST run immediately.")
620620
void matchingErrorEventsMustRunImmediately() {
621-
final String name = "matchingEventsMustRunImmediately";
621+
final String name = "matchingErrorEventsMustRunImmediately";
622622
final Consumer<EventDetails> handler = mockHandler();
623623

624624
// provider which is already in error

0 commit comments

Comments
 (0)