Closed
Labels
bugSomething isn't workingSomething isn't working
Description
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.onerrorinsrc/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,
400is the wrong code.413 Payload Too Largeis the correct one. - The limit is not enforced on a closed request.
rejectdoesn't stop the function, so moredataevents can arrive before the socket closes and keep adding tototalSize.
Steps to Reproduce
- Start the Rein server (
npm run dev). - 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"
- 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 peerif issue is valid assign me
Screenshots / Recordings (Optional)
Checklist
- I have searched for existing issues to avoid duplicates
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Activity
github-actions commentedon Nov 15, 2026
Discussions are carried on Discord.
Instead of commenting here, go to the Discord channel.
fix: return 413 for oversized uploads instead of destroying the socket (
Merge pull request #492 from RITVIKKAMASETTY/fix/upload-413-oversized