Skip to content

[Bug]: Oversized file upload destroys the socket before responding — client gets "Network error" instead of a 413 #481

Closed

Description

@RITVIKKAMASETTY

Bug Description

In src/server/signalling/handlers/fileShare.ts, parseMultipart handles the 512 MB limit like this:

// Lines 105-111
req.on("data", (chunk: Buffer) => {
	totalSize += chunk.length
	if (totalSize > MAX_FILE_BYTES) {
		req.destroy()
		reject(new Error("File too large"))
		return
	}
	chunks.push(chunk)
})

req.destroy() destroys the socket that the request and the response share. The catch block in handleFileUpload then tries to reply:

// Lines 212-214
} catch (err) {
	logger.error(`File upload error: ${String(err)}`)
	json(res, 400, { ok: false, error: String(err) })
}

Because the socket is already gone, this response never reaches the client. This causes three problems:

  • The client shows a misleading error. xhr.onerror in src/contexts/FileShareContext.tsx (line 225) fires, and the user sees "Network error during upload" instead of being told the file is too large.
  • The status code is wrong. Even if the response could be sent, 400 is the wrong code. 413 Payload Too Large is the correct one.
  • The limit is not enforced on a closed request. reject doesn't stop the function, so more data events can arrive before the socket closes and keep adding to totalSize.

Steps to Reproduce

  1. Start the Rein server (npm run dev).
  2. Open the file transfer UI and upload a file larger than 512 MB, or run:
    head -c 600000000 /dev/zero > big.bin
    curl -v -X POST http://localhost:3000/api/files/upload -F "file=@big.bin"
  3. curl reports a connection reset or an empty reply instead of a JSON error, and the web UI shows "Network error during upload".

Expected Behavior

Expected Behavior

The server should stop buffering, send a 413 with a clear error message, and close the connection only after the response is sent:

let aborted = false
req.on("data", (chunk: Buffer) => {
	if (aborted) return
	totalSize += chunk.length
	if (totalSize > MAX_FILE_BYTES) {
		aborted = true
		chunks.length = 0
		reject(new PayloadTooLargeError())
		return
	}
	chunks.push(chunk)
})

In handleFileUpload, reply 413 for that error, sending Connection: close (or calling req.destroy() after res.end()), so the client gets the message. The frontend could then show "File exceeds 512 MB limit".

Desktop Operating System

Other

Client OS and browser

All clients / Any browser

Rein Version

1.0.0

Console Logs / Error Messages (Optional)

### Console Logs / Error Messages

Server:  File upload error: Error: File too large
Client:  Error: Network error during upload
curl:    curl: (52) Empty reply from server  /  Connection reset by peer

if issue is valid assign me

Screenshots / Recordings (Optional)

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. added 2 commits that reference this issue on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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