Skip to content

[Bug]: Shared file list goes stale after SSE reconnect — deleted / expired files never removed on client #482

Closed

Description

@RITVIKKAMASETTY

Bug Description

The client keeps its shared-file list in sync through the event stream at GET /api/files/events. When a client connects, handleFileEvents in src/server/signalling/handlers/fileShare.ts (lines 397-412) replays every file in fileStore as an incoming-file event.

On the client, src/contexts/FileShareContext.tsx (lines 160-170) only ever adds files:

setSharedFiles((prev) => {
	if (prev.some((f) => f.fileId === info.fileId)) return prev
	return [info, ...prev]
})

A file is removed only when a file-deleted event arrives. EventSource reconnects automatically after Wi-Fi drops, the phone sleeps, or the server restarts, but any file-deleted events sent while the client was disconnected are lost. The replay after reconnecting only adds files and never removes any, so the client keeps entries that no longer exist on the server.

The worst case is a server restart. fileStore is in memory, so a restart empties it, yet every connected client keeps showing all the old files, and each download returns 404 File not found.

es.onerror = () => {} (line 174) also hides the disconnect completely, so nothing tells the user the list may be out of date.

Steps to Reproduce

  1. Start the Rein server and open the client on a phone.
  2. Upload a file. It appears in the shared files list.
  3. Restart the server (Ctrl+C, then npm run dev).
  4. Wait for EventSource to reconnect, which happens automatically within a few seconds.
  5. The file is still listed on the client. Tapping download returns 404 {"error":"File not found"}.

Alternative: disconnect client A from the network, delete the file from client B, then reconnect client A. Client A still shows the file.

Expected Behavior

When a client connects, the server should send one snapshot event with the full current file list instead of one incoming-file event per file:

res.write(`data: ${JSON.stringify({ type: "snapshot", files: existing })}\n\n`)

The client should replace its list with the snapshot instead of merging it in:

if (msg.type === "snapshot") {
	setSharedFiles(msg.files.map(toSharedFileInfo))
}

This brings the client back in sync on every connect and reconnect, whether the change was a deletion, a restart or anything else that happened while it was offline.

Desktop Operating System

Other

Client OS and browser

All clients / Any browser

Rein Version

1.0.0

Console Logs / Error Messages (Optional)

GET /api/files/download?fileId=<stale-id>  ->  404 {"error":"File not found"}

Screenshots / Recordings (Optional)

No response

Checklist

  • I have searched for existing issues to avoid duplicates

Activity

  1. github-actions commented on Nov 15, 2026

    @github-actions

    Discussions are carried on Discord.

    Instead of commenting here, go to the Discord channel.

  2. RITVIKKAMASETTY commented on Nov 15, 2026

    @RITVIKKAMASETTY
    ContributorAuthor

    if issue is valid please assign me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions