copyparty/tests
ed 6f8a588c4d up2k: fix a mostly-harmless race
as each chunk is written to the file, httpcli calls
up2k.confirm_chunk to register the chunk as completed, and the reply
indicates whether that was the final outstanding chunk, in which case
httpcli closes the file descriptors since there's nothing more to write

the issue is that the final chunk is registered as completed before the
file descriptors are closed, meaning there could be writes that haven't
finished flushing to disk yet

if the client decides to issue another handshake during this window,
up2k sees that all chunks are complete and calls up2k.finish_upload
even as some threads might still be flushing the final writes to disk

so the conditions to hit this bug were as follows (all must be true):
* multiprocessing is disabled
* there is a reverse-proxy
* a client has several idle connections and reuses one of those
* the server's filesystem is EXTREMELY slow, to the point where
   closing a file takes over 30 seconds

the fix is to stop handshakes from being processed while a file is
being closed, which is unfortunately a small bottleneck in that it
prohibits initiating another upload while one is being finalized, but
the required complexity to handle this better is probably not worth it
(a separate mutex for each upload session or something like that)

this issue is mostly harmless, partially because it is super tricky to
hit (only aware of it happening synthetically), and because there is
usually no harmful consequences; the worst-case is if this were to
happen exactly as the server OS decides to crash, which would make the
file appear to be fully uploaded even though it's missing some data
(all extremely unlikely, but not impossible)

there is no performance impact; if anything it should now accept
new tcp connections slightly faster thanks to more granular locking
2024-02-13 19:24:06 +00:00
..
__init__.py fix write-only volumes + add regression test 2021-04-24 02:48:41 +02:00
ptrav.py make linters happier 2023-11-30 17:33:07 +00:00
run.py make linters happier 2023-11-30 17:33:07 +00:00
test_dots.py tftp: add directory listing 2024-02-10 23:50:17 +00:00
test_dxml.py make linters happier 2023-11-30 17:33:07 +00:00
test_httpcli.py make linters happier 2023-11-30 17:33:07 +00:00
test_vfs.py list dotfiles only for specific volumes or users (#66): 2023-12-16 15:38:48 +00:00
util.py up2k: fix a mostly-harmless race 2024-02-13 19:24:06 +00:00