Periodically re-check local file size while playing - #798
Conversation
The reported file size for the current user's local file was only ever read once, at the moment the player reported the file as loaded (SyncplayClient.updateFile()). If the file kept growing on disk after that point - e.g. a media player streaming from a still-in-progress sequential/progressive download - peers would keep seeing the stale size captured at load time for the rest of the session, even after the file finished downloading. Add a lightweight periodic re-check (every FILESIZE_RECHECK_DELAY seconds, mirroring the existing askPlayer LoopingCall pattern) that re-stats the current file and re-broadcasts it only when the size actually changed, respecting the existing filename/filesize privacy settings.
|
Thanks for this. I agree with periodically re-checking the size of the currently playing local file because this prevents files that grow while playing (such as an in-progress download) from being stuck at the initial size and causing incorrect warnings to persist. The main thing I would change is when the updated size is sent. In your PR So when I tested your code with a file being downloaded it ended up outputting this: I think the periodic check should mostly observe the file, and only advertise a new size when there is a good reason to send it:
The 60 second rule is only a stability fallback. It does not mean the download is permanently complete. If a download stalls for 60 seconds, gets reported, and later resumes growing, Syncplay should continue monitoring it and can report a later matching or stable size. I would also make the filesystem check asynchronous. Proposed implementation
|
| Situation | Behaviour |
|---|---|
| File is continuously growing | Observe only; do not repeatedly call sendFile() |
| Fresh size exactly matches a valid same file peer | Send immediately |
| Fresh size matches nobody | Send after it has remained unchanged for 60 seconds |
| All other users advertise the same matching size | Send immediately; the first valid match is sufficient |
| Some users match and others are still downloading | Send immediately; unanimity is not required |
| Download stalls for 60 seconds, then resumes | The stalled size may be sent; later growth is still monitored and can be updated again |
| Loaded path changes | Reset the old stability observation |
getsize() raises OSError |
Reset the stability observation and try again on a later loop |
getsize() is slow |
Run it off the reactor; no overlapping rechecks |
Filesize privacy is DoNotSend |
Do not periodically stat the file |
Peer hides filesize (0) |
Do not use that peer for the immediate match |
| Peer hides filename | Do not use that peer for the immediate match |
| Raw or hashed privacy modes | Continue to work through existing hashing and comparison helpers |
|
@Et0h you're right, I tested this against a growing file and saw the same spam. |
…or 60s, and stat the file off the reactor thread.
|
Thanks for the new commit @mertemr - can you please summarise what tests you've done and on what operating systems. |
|
@Et0h |
Fixes #797
File size was only read once, when the file started playing (updateFile()). If the file kept growing on disk after that, the size sent to other users stayed stuck at the old value for the rest of the session.
This adds a periodic re-check (every 5s, same pattern as the existing askPlayer loop) that re-stats the current file and resends it only if the size changed. Respects the existing filesize/filename privacy settings.