Context: I’m using tusd
to handle file uploads in a production environment. My setup includes custom pre-create
and post-finish
hooks to manage file paths, metadata, and post-upload processing. The files are being uploaded to a directory structure that includes paths with special characters and spaces, and some of the paths are relatively long (up to 328 characters).
Problem: While most files are uploaded successfully, I’ve encountered an issue where some files are uploaded but end up being 0 bytes in size. The filenames are correct, and the mv
command in the post-finish
hook executes successfully, indicating that the files are being moved to the correct directory with the expected names. However, these files have no content (0 bytes), which suggests that something is going wrong during or immediately after the upload process.
Details:
- The issue does not seem to be related to the
mv
command itself, as the file names and paths are correct. - The problem occurs sporadically, with some files being uploaded successfully and others resulting in 0-byte files.
- The paths involved are long (e.g., 328 characters), and the filenames include spaces and special characters.
- My
pre-create
andpost-finish
hooks handle file metadata, date formatting, and path construction. I’ve checked these scripts for any obvious errors that might lead to the issue but haven’t found anything conclusive. - The issue might be related to the upload completion timing or filesystem handling, but I’m unsure how to diagnose further.
Steps Taken:
- Logging: I’ve added logging to the hooks to track the upload process, but the logs don’t show any errors related to the file handling. The
mv
command completes successfully, which makes it unclear why the files are 0 bytes. - Path Length Check: The paths are long, but they don’t exceed the typical 4096-character limit imposed by most Linux filesystems.
- File Permissions: I’ve verified that the user running
tusd
has the appropriate permissions to write and move files in the target directory. - Filesystem Check: Disk space is sufficient, and there don’t appear to be any obvious filesystem issues (e.g., no errors in
dmesg
or related logs).
Questions:
- Has anyone encountered a similar issue with
tusd
where files end up as 0 bytes despite successful uploads? - Could the path length or special characters in the filenames be causing issues in ways I haven’t considered?
- What additional debugging steps would you recommend to isolate the cause of these 0-byte files?
- Is there a possibility that the upload completion timing (e.g.,
tusd
finalizing the upload before the file content is fully written) could lead to this issue?
Any insights or suggestions would be greatly appreciated!