Skip to content

feat: Report a server-initiated stream close to the connection error handler - #118

Merged
beekld merged 2 commits into
mainfrom
bklimt/SDK-2802/stream-closed-by-server
Sep 29, 2026
Merged

beekld merged 2 commits into
mainfrom
bklimt/SDK-2802/stream-closed-by-server

Conversation

@beekld

@beekld beekld commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

EventSource now treats a close of the stream by the server as a connection failure, and reports it to the ConnectionErrorHandler as a new StreamClosedByServerError. Previously it did not treat that close as a failure, so the handler never ran and could not replace the built-in reconnect.

Because the default ConnectionErrorHandler returns .proceed, a consumer that does not set one now also receives the close through EventHandler.onError.


Note

Overview
When the SSE stream ends without a URL error (server closes the connection cleanly), the client now treats that as a connection failure and routes it through the same path as other connection errors.

A new public StreamClosedByServerError is introduced for that case. didCompleteWithError is refactored so both transport errors and server-initiated closes set a connectionError, then call dispatchError once—so connectionErrorHandler and (by default) EventHandler.onError run before reconnect. Client-initiated cancels (NSURLErrorCancelled from stop()) are still ignored and do not surface as this error.

Tests expect StreamClosedByServerError on normal stream finish and cover reconnect, .shutdown from the error handler, and that stop() does not report an error.

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

@beekld
beekld merged commit 30558a4 into main Sep 29, 2026
17 checks passed
@beekld
beekld deleted the bklimt/SDK-2802/stream-closed-by-server branch September 29, 2026 20:30
beekld pushed a commit that referenced this pull request Sep 29, 2026
🤖 I have created a release *beep* *boop*
---


##
[3.4.0](3.3.1...3.4.0)
(2026-09-29)


### Features

* Report a server-initiated stream close to the connection error handler
([#118](#118))
([30558a4](30558a4))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> **Release 3.4.0** — bumps the library version across the manifest,
CocoaPods spec, Xcode project, README install pins, and adds a **3.4.0**
entry to `CHANGELOG.md`.
> 
> This tag documents the functional change from
[#118](#118):
when the server ends an open SSE connection without a URL error, the
client now invokes `connectionErrorHandler` with
`StreamClosedByServerError` (instead of only logging and reconnecting).
Handlers can return `.shutdown` to stop retries, matching other
connection failures.
> 
> No Swift source edits appear in this PR; it is release metadata only.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
163099e. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: LaunchDarklyReleaseBot <LaunchDarklyReleaseBot@launchdarkly.com>
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.

3 participants