Repository navigation
fix(kt-client): a ping that cannot be sent leaves the drop to the socket's close, so a policy close is never retried (#973) - #1009
Merged
Conversation
…ket's close, so a policy close is never retried (#973) When the host closed a socket with 1008, a heartbeat ping could reach the socket while it was closing. OkHttp's send returned false, sendPing threw, and the heartbeat reported a drop with no close code, which permits a retry: the client went INTERRUPTED and reconnected, and the real 1008 close then arrived for a stale generation and was ignored. This failed "a policy close (1008) closes the client instead of reconnecting" on #1008's CI. A ping the socket refuses now ends the heartbeat quietly. The socket's close callback reports the drop with its real code. Only silence past the liveness timeout reports a drop from the heartbeat, as in the Swift and Flutter clients. The new test holds the socket in a closing state, waits for a refused ping, and only then delivers the 1008 close. Before this change the refused ping started a reconnect, so the test's connect-count check fails. Refs #973
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.
The Kotlin bridge client no longer reconnects after a policy close (1008) that happens while a heartbeat ping is being sent. This fixes a race from #993 that failed the Kotlin job on #1008's CI.
Only silence past 45 seconds is a drop the heartbeat reports
INTERRUPTED, reconnectsendreturns false: it is closing)INTERRUPTED, reconnectThis matches the Swift (
try? await sendRaw) and Flutter (_sendPing: "a failed send means the socket is closing; its close is the drop") clients. ADR-0019's heartbeat amendment does not say a failed send is a drop, so it does not change.Risk
sendreturns false only after a close has started or the socket has failed, and both report throughonClosing/onClosed/onFailure, so the drop is still reported.Integration evidence
Unit evidence only: no CI job runs a native client against a real host. The new test forces the race's order on the fake socket (
FakeReconnectSocket.beginClosing()makessendreturn false without reporting a close;finishClosing(1008)reports it later)."Native SDK conformance (kotlin)" passed three times on ecd78fe, with the new test and all 34
BridgeReconnectTestcases passing: job 116641275127, and re-runs 116654616946 and 116655525208. The job is non-blocking, soCI / requireddoes not reflect it.Implementation notes
BridgeHeartbeat.beattreats a ping that returns false or throws as the end of the heartbeat, never as silence.onSilentruns only when the silence check passes the timeout. Thestartdoc says so.PyricBridgeClient.sendPingreturns the transport'ssendresult instead of throwing on false.a ping refused by a closing socket leaves the drop to its close, so a policy close is not retried. It waits for a refused ping, waits 100 ms, and asserts the client is stillATTACHEDwith one connect call. Then it delivers 1008 and assertsCLOSED, one attach and one connect call. On the previous code the refused ping threw,onSilentcalledhandleConnectionLoss(closeCode = null), a retry was permitted, and the 5 ms reconnect delay produced a second connect call well within the 100 ms, so the connect-count assertion fails. If the client had re-attached, the later 1008 would have been delivered to a stale generation, soCLOSEDwould also never come.sendreturns true, so they still reach the timeout andonSilent. Inno ping reaches a socket after it drops or after disconnect, a ping that races the drop is now refused quietly instead of reporting a stale drop.Refs #973