tus / tusd

Reference server implementation in Go of tus: the open protocol for resumable file uploads
https://tus.github.io/tusd
MIT License
2.92k stars 465 forks source link

`InternalServerError: no such file or directory` when Downloading file with using File Locker. #1148

Closed 134130 closed 6 days ago

134130 commented 6 days ago

Describe the bug

To Reproduce Steps to reproduce the behavior:

  1. Make your tusd server with http://127.0.0.1:8080/basedir
  2. curl 127.0.0.1:8080/basedir/some/your/sub-directory/file.jpeg
  3. See error: msg=InternalServerError message="open <Eliminated>/some/your/sub-directory/file.jpeg.lock.1967546860: no such file or directory"

Expected behavior

Setup details Please provide following details, if applicable to your situation:


func (handler *UnroutedHandler) GetFile(http.ResponseWriter, *http.Request) {
    // ...
    if handler.composer.UsesLocker {
        lock, err := handler.lockUpload(c, id) // <-- (1)
        if err != nil {
            handler.sendError(c, err)
            return
        }

        defer lock.Unlock()
    }
    // ...
}

func (handler *UnroutedHandler) lockUpload(c *httpContext, id string) (Lock, error) {
    // ...
    if err := lock.Lock(ctx, releaseLock); err != nil { // <-- (2)
        return nil, err // <-- (3) *fs.PathError (ENOENT)
    }
    // ...
}
Acconut commented 6 days ago

Thank you for reporting this. I opened https://github.com/tus/tusd/pull/1149 to fix this by including a check in filelocker. I agree with your concerns that this might not be the best place for this check as filelocker should not directly rely on the folder structure that is created by the filestore. However, this is currently already the case and filelocker will put the .lock file next to the .info file in the directory created by filestore. We can revisit this architecture in the future and decide if we want to decouple them more.