Skip to content

Commit

Permalink
fix: possible issue with concurrency for activation dynamic event sou…
Browse files Browse the repository at this point in the history
…rce registration (#2222)



Signed-off-by: Attila Mészáros <csviri@gmail.com>
  • Loading branch information
csviri authored Jan 29, 2024
1 parent 2366987 commit 7d17e4c
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,22 @@ protected AbstractEventSourceHolderDependentResource(Class<R> resourceType) {
this.resourceType = resourceType;
}

public Optional<T> eventSource(EventSourceContext<P> context) {
/**
* Method is synchronized since when used in case of dynamic registration (thus for activation
* conditions) can be called concurrently to create the target event source. In that case only one
* instance should be created, since this also sets the event source, and dynamic registration
* will just start one with the same name. So if this would not be synchronized it could happen
* that multiple event sources would be created and only one started and registered. Note that
* this method does not start the event source, so no blocking IO is involved.
*/
public synchronized Optional<T> eventSource(EventSourceContext<P> context) {
// some sub-classes (e.g. KubernetesDependentResource) can have their event source created
// before this method is called in the managed case, so only create the event source if it
// hasn't already been set.
// The filters are applied automatically only if event source is created automatically. So if an
// event source
// is shared between dependent resources this does not override the existing filters.

if (eventSource == null && eventSourceNameToUse == null) {
setEventSource(createEventSource(context));
applyFilters();
Expand Down

0 comments on commit 7d17e4c

Please sign in to comment.