Skip to content

Commit ef87160

Browse files
committed
race condition fix
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 7b1fb37 commit ef87160

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/AbstractWorkflowExecutor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ protected <R> void submit(
174174
DependentResourceNode<R, P> dependentResourceNode,
175175
NodeExecutor<R, P> nodeExecutor,
176176
String operation) {
177+
logger()
178+
.debug("Submitting to {}: {} primaryID: {}", operation, dependentResourceNode, primaryID);
177179
final Future<?> future = executorService.submit(nodeExecutor);
178180
markAsExecuting(dependentResourceNode, future);
179-
logger()
180-
.debug("Submitted to {}: {} primaryID: {}", operation, dependentResourceNode, primaryID);
181181
}
182182

183183
protected <R> void registerOrDeregisterEventSourceBasedOnActivation(

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,13 @@ public void handleRecentResourceCreate(ResourceID resourceID, R resource) {
183183

184184
@Override
185185
public Optional<R> get(ResourceID resourceID) {
186-
var res = cache.get(resourceID);
186+
// order of these two resource gets matter, since other way around
187+
// there can be a race condition that we read the resource from the cache
188+
// it is not found. But, right after that we process an event for the informer that
189+
// evicts the temporal resource cache, so at the end resource won't be found in temp cache
190+
// however it is there already in informer cache at that moment.
187191
Optional<R> resource = temporaryResourceCache.getResourceFromCache(resourceID);
192+
var res = cache.get(resourceID);
188193
if (comparableResourceVersions
189194
&& resource.isPresent()
190195
&& res.filter(

sample-operators/mysql-schema/src/test/java/io/javaoperatorsdk/operator/sample/MySQLSchemaOperatorE2E.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void test() {
127127
.delete();
128128

129129
await()
130-
.atMost(2, MINUTES)
130+
.atMost(4, MINUTES)
131131
.ignoreExceptions()
132132
.untilAsserted(
133133
() -> {

0 commit comments

Comments
 (0)