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

http-netty: Add phantom reference version of watchdog filters #3084

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bryce-anderson
Copy link
Contributor

Motivation

The current watchdog filters are not exact: they don't account for responses that get drained later than the cleaner expects which can result in false positives. Because of this they can't proactively drain the responses.

Modifications

Add a PhantomReference variant of the watchdog filters. This filter uses a PhantomReference based implementation to be certain the response has been abandoned. Because we can now be certain, we can also proactively drain the response.

Motivation

The current watchdog filters are not exact: they don't account for
responses that get drained later than the cleaner expects which can
result in false positives. Because of this they can't proactively
drain the responses.

Modifications

Add a PhantomReference variant of the watchdog filters. This filter
uses a PhantomReference based implementation to be certain the
response has been abandoned. Because we can now be certain, we can
also proactively drain the response.
}
};
// This implementation uses an atomic reference stored on the context to track when requests have been leaked.
// It is efficient and doesn't depend on GC, but may be prone to false positives since its possible that the
Copy link
Member

Choose a reason for hiding this comment

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

As we discussed offline:
HttpMessageDiscardWatchdogClientFilter logs only in 2 use-cases:

  1. When we detect a new retry but the previous response was not drained. We expect that previous response payload is always drained before the retry is initiated.
  2. When we detect onError at the outer client filter (close to the user) after we received response meta-data in the inner connection filter (close to channel).

In both cases the previous response is not available anymore and can not be drained later. The false positives are unlikely.

The PhantomReference approach might be helpful to cover more use-cases, like when users use streaming responses, successfully got the response metadata from the client, but then forgot to drain it later in the users scope. However, having 2 different approaches will increase the runtime cost (watchdog already adds visible overhead). On the other hand, removing watchdog and replacing it with PhantomReference at NettyChannelPublisher level will not allow us distinguish (1) from (2). Idk... Let's chat more about it on the team sync.

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.

2 participants