fix #4884: using different threads for watch events #4900
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fix #4884
This addresses #4884 for watch events. After looking over the ResourceEventHandler logic again, I remembered why this wasn't done initially - for most Informer processing this will introduce an extra / unnecessary thread hop. Removing the Informer SerialExecutor however is not possible, because there is still the resync to contend with and the list processing is handled in completion events that may be on the main or http client thread.
Similarly for any users that have taken responsibility for threading concerns, this wrapping will also be unnecessary.
Also the wrapping is (mostly) unnecessary for okhttp as it uses a thread per websocket - but does also use that thread to handle the ping/pong.
Alternatives to always wrapping would include using a Watcher method or annotation to declare whether async handling is needed, or a method like KubernetesClient.asyncWatcher(Watcher) that returns a wrapped Watcher.
@manusa @rohanKanojia do you want to make this behavior explicit or always make Watch handling async?
Type of change
test, version modification, documentation, etc.)
Checklist