Skip to content

SSE ConnectionRegistry doesn't clean up dead connections on send failure #243

Description

@jhodapp

Problem

When an SSE connection dies ungracefully (network drop, browser crash, tab close), the ConnectionRegistry never removes the stale entry. send_to_user in sse/src/connection.rs logs a warning when sender.send() fails but doesn't unregister the connection. Dead entries accumulate until server restart.

Current behavior

  1. Client disconnects ungracefully
  2. tx sender remains in the registry
  3. Every subsequent event triggers: "Failed to send event to connection..." — but no cleanup happens
  4. Warnings repeat on every event until server restart

Fix options

Option A: Lazy cleanup in send_to_user

Collect failed connection IDs during iteration, then call unregister for each after the loop completes. Avoids DashMap deadlocks from mutating during iteration. Simple, no new tasks or timers.

Option B: Periodic sweeper task

Background tokio::spawn that periodically iterates connections and removes ones where sender.is_closed() returns true. Doesn't complicate the send path, but adds a background task to manage.

Files

  • sse/src/connection.rssend_to_user (line ~101) and broadcast (line ~118) both have this gap

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions