Repository navigation
fix(gun): release a server stream the caller stops reading - #659
Open
Raed2180416 wants to merge 1 commit into
Open
Raed2180416 wants to merge 1 commit into
Raed2180416 wants to merge 1 commit into
Conversation
Raed2180416
force-pushed
the
fix/gun-release-abandoned-stream
branch
from
November 18, 2026 09:06
da0c661 to
bee8fd1
Compare
polvalente
approved these changes
Nov 20, 2026
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.
A server-streaming reply that the caller stops reading before it ends is never released: the stream stays open on the connection, and its response process keeps the rest of the reply queued for as long as the connection lives.
response_stream/4ingrpc/lib/grpc/client/adapters/gun.exreturns the reply as aStream.unfold/2.unfoldhas no cleanup hook, so when the consumer halts early —Enum.take/2,Stream.take/2, aforwith abreak, or an exception in the caller's own code — nothing cancels the stream and nothing stops theStreamResponseProcessthat buffers it. The connection process still holds the stream inresponse_processes, the process still holds the frames already delivered, and Gun has no reason to reset a stream nobody is reading. The only thing that eventually clears it is the deadline timer, and with:infinity(the default when no timeout is given) there is no timer at all.Stopping early is the only way to abandon a reply: the enumeration returns a plain enumerable, not the
GRPC.Client.StreamthatGRPC.Stub.cancel/1takes, so a caller who has read enough has no way to cancel it.The reply is now a
Stream.resource/3whose after-function cancels the stream, so releasing it happens on halt and on an exception in the consumer as well as on normal completion. The after-function only cancels a stream that has not already seen its trailers or an error, so nothing changes for a reply that is read to the end.Verified:
MIX_ENV=test mix test test/grpc/adapters/gun_abandoned_stream_test.exs— before the change the connection process still tracks the response process of a stream the test took one message from (response_processesholds one entry), after the change it is empty.MIX_ENV=test mix test— 706 passed, 2 skipped.mix format --check-formatted— clean.