Skip handling when handler is closed to prevent processing on canceled calls#820
Open
HyprUsr wants to merge 1 commit intogrpc:masterfrom
Open
Skip handling when handler is closed to prevent processing on canceled calls#820HyprUsr wants to merge 1 commit intogrpc:masterfrom
HyprUsr wants to merge 1 commit intogrpc:masterfrom
Conversation
70b8dac to
64b3c0c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR fixes a critical server-side crash occurring when a gRPC client disconnects immediately after initiating a request. This issue typically results in an unhandled
Bad state: Cannot add event after closingerror, which brings down the entire server process.Related Issues
Fixes #67 and #558 . This behavior has been reported previously but remained unresolved until now.
The Problem
When a client terminates abruptly (e.g., a process crash or network drop) immediately after sending a request, the server-side stream may transition to a closed state while the handler is still attempting to send data or events back. Attempting to interact with the closed stream without a state check throws a fatal "Bad state" exception.
As a matter of principle, a client-side disconnection should never be able to compromise the stability of the server process.
The Solution
The fix introduces a safety check on the isCanceled flag prior to any interaction with the client stream. This ensures that if the connection is already dead, the server gracefully handles the state rather than attempting to write to a closed sink.
How to Reproduce