Skip to content

fix: Emit an error when the stream closes before any response#111

Merged
keelerm84 merged 1 commit into
4.xfrom
mk/SDK-2676/linux-redirect-error
Jul 16, 2026
Merged

fix: Emit an error when the stream closes before any response#111
keelerm84 merged 1 commit into
4.xfrom
mk/SDK-2676/linux-redirect-error

Conversation

@keelerm84

@keelerm84 keelerm84 commented Jul 15, 2026

Copy link
Copy Markdown
Member

On Linux, swift-corelibs-foundation (libcurl) terminates a 3xx redirect with an
empty or missing Location header by completing the task with no error and no
response -- no didReceive, no willPerformHTTPRedirection callback. EventSource
treated that as a normal close and reconnected forever, never emitting an error,
so the SSE contract tests "client handles empty/missing Location header with
301/307 status" timed out. (CFNetwork surfaces it as an error, so macOS passed.)

Treat a no-error completion that never opened the stream as an unrecoverable
error and stop, giving deterministic behavior across platforms. Adds a
regression test that finishes a request with no response and asserts an
unrecoverable error with no reconnect.


Note

Medium Risk
Changes connection teardown in didCompleteWithError for a narrow edge case; misclassification could stop valid reconnects or still loop, but scope is limited to tasks that never reached .open.

Overview
Fixes infinite reconnect when a URLSession task completes successfully but never delivers headers (so readyState never becomes .open). On Linux/libcurl this happens for 3xx redirects with empty or missing Location; macOS often reports an error instead.

In urlSession(_:task:didCompleteWithError:), a new branch treats no error + never opened as an unrecoverable EventSourceError, sets shutdown, finishes the stream, and skips the reconnect loop.

Adds closeWithoutResponseEmitsUnrecoverableError to finish a mock request without responding and assert a non-recoverable error with no follow-up request.

Reviewed by Cursor Bugbot for commit 71de077. Bugbot is set up for automated code reviews on this repo. Configure here.

@keelerm84 keelerm84 marked this pull request as ready for review July 15, 2026 20:02
@keelerm84 keelerm84 requested a review from a team as a code owner July 15, 2026 20:02
On Linux, swift-corelibs-foundation (libcurl) terminates a 3xx redirect with an
empty or missing Location header by completing the task with no error and no
response -- no didReceive, no willPerformHTTPRedirection callback. EventSource
treated that as a normal close and reconnected forever, never emitting an error,
so the SSE contract tests "client handles empty/missing Location header with
301/307 status" timed out. (CFNetwork surfaces it as an error, so macOS passed.)

Treat a no-error completion that never opened the stream as an unrecoverable
error and stop, giving deterministic behavior across platforms. Adds a
regression test that finishes a request with no response and asserts an
unrecoverable error with no reconnect.
@keelerm84 keelerm84 force-pushed the mk/SDK-2676/linux-redirect-error branch from dc078d0 to 71de077 Compare July 15, 2026 20:32
@keelerm84 keelerm84 merged commit 7f4398a into 4.x Jul 16, 2026
16 checks passed
@keelerm84 keelerm84 deleted the mk/SDK-2676/linux-redirect-error branch July 16, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants