Fix unreliable timeout #376
Open
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.
Fix: Notify caller when channel becomes inactive unexpectedly
Problem
When network connectivity is lost (e.g., 100% packet loss), requests hang indefinitely instead of timing out or returning an error. This is a regression
introduced in v1.1.0.
Potential fix for #361
Root Cause
When network drops, NIO's HTTP/2 layer detects the connection loss and triggers
channelInactivebefore theIdleStateHandlercan fire its timeout event.However,
channelInactiveonly closed the connection without notifying the caller:This worked in v1.0.4 because the retain cycle (fixed in #354) kept handlers alive longer, giving IdleStateHandler time to fire. With the fix, cleanup happens faster and
channelInactivewins the race—but doesn't notify the caller.Solution
hasRespondedflag to track whether the response callback has been invokedchannelInactiveto call the response callback with.unavailableerror if no response was received yetChanges
ConnectUnaryChannelHandler.swift: AddedhasRespondedflag and updatedchannelInactiveConnectStreamChannelHandler.swift: AddedhasRespondedflag and updatedchannelInactiveTesting
Tested with Network Link Conditioner at 100% packet loss: