anacrolix / confluence

Torrent client as a HTTP service
Mozilla Public License 2.0
236 stars 32 forks source link

Panic when making file state request when file doesn't exists #6

Closed arranlomas closed 7 years ago

arranlomas commented 7 years ago

seems to happen when I clear the storage the make a request for the file state but the torrent directory has been deleted. I have only tested this on android, would be to get a similar response you would at the data endpoint - file not found message

runtime error: invalid memory address or nil pointer dereference goroutine 6816 [running]: net/http.(conn).serve.func1(0x44201f5a00) D:/Go/src/net/http/server.go:1491 +0x98 panic(0x75663216c0, 0x442000c040) D:/Go/src/runtime/panic.go:458 +0x4c0 github.com/anacrolix/torrent.(File).State(0x0, 0x0, 0x0, 0x0) D:/Go/projects/src/github.com/anacrolix/torrent/file.go:57 +0x30 github.com/anacrolix/confluence/confluence.fileStateHandler(0x75665868e0, 0x44202a95f0, 0x44200e02d0) D:/Go/projects/src/github.com/anacrolix/confluence/confluence/handlers.go:80 +0x11c net/http.HandlerFunc.ServeHTTP(0x75663a4920, 0x75665868e0, 0x44202a95f0, 0x44200e02d0) D:/Go/src/net/http/server.go:1726 +0x38 github.com/anacrolix/confluence/confluence.withTorrentContext.func1(0x75665868e0, 0x44202a95f0, 0x44200e01e0) D:/Go/projects/src/github.com/anacrolix/confluence/confluence/middlewares.go:45 +0x498 net/http.HandlerFunc.ServeHTTP(0x4420180cc0, 0x75665868e0, 0x44202a95f0, 0x44200e01e0) D:/Go/src/net/http/server.go:1726 +0x38 net/http.(ServeMux).ServeHTTP(0x442017ac90, 0x75665868e0, 0x44202a95f0, 0x44200e01e0) D:/Go/src/net/http/server.go:2022 +0x178 github.com/anacrolix/confluence/confluence.(Handler).ServeHTTP(0x442016f230, 0x75665868e0, 0x44202a95f0, 0x44200e01e0) D:/Go/projects/src/github.com/anacrolix/confluence/confluence/handler.go:19 +0x1a8 net/http.serverHandler.ServeHTTP(0x4420176900, 0x75665868e0, 0x44202a95f0, 0x442045e000) D:/Go/src/net/http/server.go:2202 +0x154 net/http.(conn).serve(0x44201f5a00, 0x7566587360, 0x4420318ac0) D:/Go/src/net/http/server.go:1579 +0xda8 created by net/http.(Server).Serve D:/Go/src/net/http/server.go:2293 +0x470

anacrolix commented 7 years ago

It would appear you have requested a file that doesn't exist in the torrent, at least with the display path you have used.

arranlomas commented 7 years ago

Yup, so would it reasonable to respond with file not found? Or is panic a fair response in this case

anacrolix commented 7 years ago

I think 404 is right here, I have a fix coming.