Drop response handler if request is canceled/dropped#247
Conversation
Summary of ChangesHello @imabdulbasit, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to cancel request handlers when the client disconnects. This is achieved by racing the handler future against a new wait_for_disconnect future that polls the TCP stream for closure. The implementation is sound and includes a new test case to verify the behavior. I have a couple of suggestions to improve code quality and maintainability in the new wait_for_disconnect function and its corresponding test.
jbearer
left a comment
There was a problem hiding this comment.
IIUC this would be a breaking change because it requires that handler futures are cancel safe, which wouldn't have been required before. Are we confident this isn't gonna break anything downstream?
| return; | ||
| } | ||
| Err(e) => { | ||
| tracing::debug!(%e, "client disconnected (error on peek)"); |
There was a problem hiding this comment.
Does an error in peek necessarily mean a client disconnect? If it's possible that future reads from the socket would succeed even after this failure (ie a transient failure), then we should not disconnect here
There was a problem hiding this comment.
I am not sure, but I can match the exact error types
| } | ||
|
|
||
| #[async_trait] | ||
| impl<State> Listener<State> for RateLimitListener<State> |
There was a problem hiding this comment.
So we're only doing this for RateLimitListener. Do you know if the standard listener (whatever you get if you just pass in a &str like "0.0.0.0:{port}") already has this behavior? If not, it might be better to do this as a mix-in adapter, that we could use like HandleDisconnectListener<RateLimitListener<State>> or HandleDisconnectListener<StandardListener>
There was a problem hiding this comment.
yeah we have the same issue with standard listener, but the confirmation layer uses RateLimitListener, so I thought to make the change to RateLimitListener only.
I tried compiling the confirmation layer and it worked without any issues. |
|
It's not a compilation issue. Things can go wrong at runtime if futures that aren't cancel-safe are cancelled (e.g. some futures don't/can't clean up all their resources properly in |
When a client disconnects before a response is sent, the handler future previously ran to completion. This was problematic for handlers that acquire resources such as database. This would mean that we are unnecessarily causing load on database, and in some cases can not serve new requests.
This PR adds client-disconnect detection in the listener and cancels/drops the response handler when the socket closes.