Skip to content

fix: possible issue with concurrency for activation dynamic event source registration #2222

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

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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