Surface request-stream defects in Zio client streaming#110
Merged
Conversation
catchAll only recovers the typed StatusException channel, so a defect (Cause.Die) in the request stream — e.g. a throwing map or iterator — skipped call.cancel and listener.promise.fail. The forkDaemon'd sender died silently while promise.await blocked forever, hanging the call and leaking the ClientCall and fiber. Use catchAllCause so defects also cancel the call and complete the promise, matching the fs2 and Kyo backends.
catchAllCause also intercepts interruption, so on the early-response path (the server closes before the request stream is drained) the interrupted sender ran call.cancel and promise.failCause instead of terminating cleanly. Re-raise interruption-only causes so only real failures and defects are surfaced via the promise; the defect-handling fix is unchanged.
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.
Problem
In
ZioClientBackend.clientStreamingRun, the request-sending effect is guarded withcatchAll:catchAllrecovers only the typed error channel (E = StatusException). If the user's request stream raises a defect (Cause.Die) rather than a typed failure — amap/mapZIOthat throws,ZStream.fromIteratorover a throwing iterator, etc. — the handler never runs. So:call.cancel(...)andcall.halfClose()never execute → the server keeps waiting for messages and never sendsonClose;listener.promise.fail(e)never runs →promise.awaitis never completed;forkDaemon'd, so its death is not propagated to the parent.With
CallOptions.DEFAULT(no deadline) the call hangs indefinitely, leaking theClientCalland the awaiting fiber. The fs2 (handleErrorWith) and Kyo (Result.Panic) backends already handle this case; Zio was the outlier.Fix
Use
catchAllCause, which recovers both typed failures and defects.cause.squashyields aThrowableforcall.cancel, andpromise.failCause(cause)preserves the original cause (typed or defect). The normal typed-error path is unchanged.Test
Added a regression test that runs a client-streaming call whose request stream dies with a defect. Pre-fix it hangs forever; post-fix it completes in ~200ms. The test uses
@@ TestAspect.withLiveClockso the.timeoutguard runs against real time rather than the frozenTestClock.