This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
Synapse can fail to move large media uploads from temporary storage to disk in time before the client disconnects #13009
Labels
A-Media-Repository
Uploading, downloading images and video, thumbnailing
O-Occasional
Affects or can be seen by some users regularly or most users rarely
S-Major
Major functionality / product severely impaired, no satisfactory workaround.
T-Defect
Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
This issue is a distilled version of #12937.
When a file is uploaded to Synapse's media store, Twisted buffers it into a temporary file and gives Synapse an
IO
handle to it once it's been fully received.The issue is that, with sufficiently large files and slow storage, it's possible that it will take more than 30 seconds to copy the bytes out of that temporary file into the correct location in the media store.
Clients such as Element Web will time out 30 seconds after having sent the last byte. (It also wouldn't seem unusual for a reverse proxy to do something similar.)
When this happens, the disconnection causes Twisted to close the temporary file and so Synapse's copy is interrupted.
The error produced in the logs looks as follows:
We would benefit overall by writing the bytes straight into a file on the correct filesystem as they're received from the client (either to the correct location, or to a temporary location with a rename operation upon completion). This would also mean that the client doesn't have to 'wait around' for the file copy to happen, since it's been happening during the upload (and in most cases, disk I/O is probably faster than the client's upload speed anyway!). In short: it will reduce upload latency a bit for large files.
(An uglier workaround would be to prevent the file copy from blocking the response, returning the MXC URL before it's even ready and finishing the copy in the background. I don't think it's great to give an MXC URL that's not ready — it could lead to races.)
Either solution probably involves some amount of spelunking into how Twisted manages these temporary files.
The text was updated successfully, but these errors were encountered: