Skip to content
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

Detect unexpected response leaks for multi-address client instances #3096

Merged
merged 3 commits into from
Nov 11, 2024

Conversation

idelpivnitskiy
Copy link
Member

@idelpivnitskiy idelpivnitskiy commented Nov 9, 2024

Motivation:

We already apply HttpMessageDiscardWatchdogClientFilter to single-address clients to detect response leaks that could be caused by unhandled exceptions in the filter chain. Multi-address client adds more logic around a client group and therefore also could leak responses if case on unexpected exceptions.

Modifications:

  • Apply HttpMessageDiscardWatchdogClientFilter to multi-address client instances;
  • Enhance HttpMessageDiscardWatchdogClientFilter to include unhandled exception in the logs to help narrow down the leak cause;
  • CleanerStreamingHttpClientFilterFactory: replace onErrorResume with whenOnError to reduce RS overhead (avoids subscribe sequence for returned failed single);

Result:

Users will see warn message if their multi-address client leaks responses.

Motivation:

We already apply `HttpMessageDiscardWatchdogClientFilter` to
single-address clients to detect response leaks that could be caused by
unhandled exceptions in the filter chain. Multi-address client adds more
logic around a client group and therefore also could leak responses if
case on unexpected exceptions.

Modifications:

- Apply `HttpMessageDiscardWatchdogClientFilter` to multi-address client
instances;
- Enhance `HttpMessageDiscardWatchdogClientFilter` to include unhandled
exception in the logs to help narrow down the leak cause;

Result:

Users will see warn message if their multi-address client leaks
responses.
@@ -135,6 +135,9 @@ public StreamingHttpClient buildStreaming() {
urlClient = redirectConfig == null ? urlClient :
new RedirectingHttpRequesterFilter(redirectConfig).create(urlClient);

// Detect leaks that can be caused by unexpected exceptions
urlClient = HttpMessageDiscardWatchdogClientFilter.CLIENT_CLEANER.create(urlClient);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this results in 2 cleaners. Maybe it's not a big deal, but just wanted to be sure I understood what the structure will be.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, because from a single address client we don't know if it's a standalone instance or part of the multi-address client group we can not remove it from there. So, for multi-address flow we will have 2 cleaners for onError case:

  1. Last one before returning from single-address level.
  2. Last one before returning from multi-address level to the users.

This should not be a big deal because the watchdog overhead mostly comes from the connection level filter that instantiates AtomicReference for each request and transforms response message body for each response. The overhead of CleanerStreamingHttpClientFilterFactory is negligible bcz onError handling is super cheap and happens only in case of exceptions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sent a new commit to also replace onErrorResume with whenOnError. It will help to reduce overhead (avoids subscribe sequence for returned failed single).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was suggesting we could make the Single client aware if it gets instantiated from a multi client, but your explanation makes me think it's probably not a big deal. Let's be sure and check the perf stats after merge.

@idelpivnitskiy idelpivnitskiy merged commit 8fd62da into apple:main Nov 11, 2024
11 checks passed
@idelpivnitskiy idelpivnitskiy deleted the multi-address-leak-detector branch November 11, 2024 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants