-
Notifications
You must be signed in to change notification settings - Fork 74
feat: Propagate fatal error on wait for init #1681
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
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 | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |||||||||||||||||||||||||||||||||
| import dev.openfeature.sdk.EvaluationContext; | ||||||||||||||||||||||||||||||||||
| import dev.openfeature.sdk.ImmutableContext; | ||||||||||||||||||||||||||||||||||
| import dev.openfeature.sdk.ProviderEvent; | ||||||||||||||||||||||||||||||||||
| import dev.openfeature.sdk.ProviderEventDetails; | ||||||||||||||||||||||||||||||||||
| import dev.openfeature.sdk.exceptions.FatalError; | ||||||||||||||||||||||||||||||||||
| import dev.openfeature.sdk.exceptions.GeneralError; | ||||||||||||||||||||||||||||||||||
| import lombok.Getter; | ||||||||||||||||||||||||||||||||||
|
|
@@ -15,10 +16,10 @@ | |||||||||||||||||||||||||||||||||
| @Getter | ||||||||||||||||||||||||||||||||||
| class FlagdProviderSyncResources { | ||||||||||||||||||||||||||||||||||
| @Setter | ||||||||||||||||||||||||||||||||||
| private volatile ProviderEvent previousEvent = null; | ||||||||||||||||||||||||||||||||||
| private volatile ProviderEvent previousEvent; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @Setter | ||||||||||||||||||||||||||||||||||
| private volatile boolean isFatal; | ||||||||||||||||||||||||||||||||||
| private volatile ProviderEventDetails fatalProviderEventDetails; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| private volatile EvaluationContext enrichedContext = new ImmutableContext(); | ||||||||||||||||||||||||||||||||||
| private volatile boolean isInitialized; | ||||||||||||||||||||||||||||||||||
|
|
@@ -39,7 +40,6 @@ public synchronized boolean initialize() { | |||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| this.isInitialized = true; | ||||||||||||||||||||||||||||||||||
| this.isFatal = false; | ||||||||||||||||||||||||||||||||||
| this.notifyAll(); | ||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
@@ -68,7 +68,7 @@ public synchronized boolean initialize() { | |||||||||||||||||||||||||||||||||
| public void waitForInitialization(long deadline) { | ||||||||||||||||||||||||||||||||||
| long start = System.currentTimeMillis(); | ||||||||||||||||||||||||||||||||||
| long end = start + deadline; | ||||||||||||||||||||||||||||||||||
| while (!isInitialized && !isShutDown) { | ||||||||||||||||||||||||||||||||||
| while (!isInitialized && !isShutDown && !isFatal) { | ||||||||||||||||||||||||||||||||||
| long now = System.currentTimeMillis(); | ||||||||||||||||||||||||||||||||||
| // if wait(0) is called, the thread would wait forever, so we abort when this would happen | ||||||||||||||||||||||||||||||||||
| if (now >= end) { | ||||||||||||||||||||||||||||||||||
|
|
@@ -77,7 +77,7 @@ public void waitForInitialization(long deadline) { | |||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| long remaining = end - now; | ||||||||||||||||||||||||||||||||||
| synchronized (this) { | ||||||||||||||||||||||||||||||||||
| if (isShutDown) { | ||||||||||||||||||||||||||||||||||
| if (isShutDown || isFatal) { | ||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (isInitialized) { // might have changed in the meantime | ||||||||||||||||||||||||||||||||||
|
|
@@ -91,12 +91,16 @@ public void waitForInitialization(long deadline) { | |||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if (isShutDown) { | ||||||||||||||||||||||||||||||||||
| String msg = "Already shut down due to previous error."; | ||||||||||||||||||||||||||||||||||
| if (isFatal) { | ||||||||||||||||||||||||||||||||||
| throw new FatalError(msg); | ||||||||||||||||||||||||||||||||||
| if (isFatal) { | ||||||||||||||||||||||||||||||||||
| var fatalEvent = fatalProviderEventDetails; | ||||||||||||||||||||||||||||||||||
| if (fatalEvent != null) { | ||||||||||||||||||||||||||||||||||
| throw new FatalError("Initialization failed due to a fatal error: " + fatalEvent.getMessage()); | ||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||
| throw new FatalError("Initialization failed due to a fatal error."); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| throw new GeneralError(msg); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+94
to
+101
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. The To ensure the correct error code is propagated, you should use a constructor that accepts an
Suggested change
Contributor
Author
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. I assume that the user only invokes |
||||||||||||||||||||||||||||||||||
| if (isShutDown) { | ||||||||||||||||||||||||||||||||||
| throw new GeneralError("Already shut down due to previous error."); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -107,4 +111,10 @@ public synchronized void shutdown() { | |||||||||||||||||||||||||||||||||
| isShutDown = true; | ||||||||||||||||||||||||||||||||||
| this.notifyAll(); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| public synchronized void fatalError(ProviderEventDetails providerEventDetails) { | ||||||||||||||||||||||||||||||||||
| isFatal = true; | ||||||||||||||||||||||||||||||||||
| fatalProviderEventDetails = providerEventDetails; | ||||||||||||||||||||||||||||||||||
| this.notifyAll(); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.