Skip to content

Commit 7d17e4c

Browse files
authoredJan 29, 2024
fix: possible issue with concurrency for activation dynamic event source registration (#2222)
Signed-off-by: Attila Mészáros <[email protected]>
1 parent 2366987 commit 7d17e4c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed
 

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractEventSourceHolderDependentResource.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,22 @@ protected AbstractEventSourceHolderDependentResource(Class<R> resourceType) {
3434
this.resourceType = resourceType;
3535
}
3636

37-
public Optional<T> eventSource(EventSourceContext<P> context) {
37+
/**
38+
* Method is synchronized since when used in case of dynamic registration (thus for activation
39+
* conditions) can be called concurrently to create the target event source. In that case only one
40+
* instance should be created, since this also sets the event source, and dynamic registration
41+
* will just start one with the same name. So if this would not be synchronized it could happen
42+
* that multiple event sources would be created and only one started and registered. Note that
43+
* this method does not start the event source, so no blocking IO is involved.
44+
*/
45+
public synchronized Optional<T> eventSource(EventSourceContext<P> context) {
3846
// some sub-classes (e.g. KubernetesDependentResource) can have their event source created
3947
// before this method is called in the managed case, so only create the event source if it
4048
// hasn't already been set.
4149
// The filters are applied automatically only if event source is created automatically. So if an
4250
// event source
4351
// is shared between dependent resources this does not override the existing filters.
52+
4453
if (eventSource == null && eventSourceNameToUse == null) {
4554
setEventSource(createEventSource(context));
4655
applyFilters();

0 commit comments

Comments
 (0)
Please sign in to comment.