Closed scarfacedeb closed 5 years ago
I see... So Cowboy 2 is killing the response process before the whole file has been completely sent, while Cowboy 1 kept the process around until the file was finished?
Looking at the Cowboy code, it looks like there's a way to disable the kernel sendfile and fall back to a compatibility layer, I wonder if disabling it would result in the same problem?
Anyways, I suppose the best way right now is the way you've implemented it in the commit -- I really don't want to keep track of old files and clean them up occasionally -- that just seems like a lot more complexity. It might come down to that, though...
After I updated
cowboy
to v2, I discovered that most of the processed files served byExfile
stopped rendering.It only happens with requests that have image processing specified in the url.
I think that the issue is caused by the combination of
Exfile.Tempfile
use for the image processing andPlug.Conn.send_file/3
for sending the response.I created an example app to narrow down the issue: https://github.com/scarfacedeb/exfile_sendfile_example.
master
branch usescowboy 2
and has the issue.cowboy1
branch usescowboy 1
and doesn't have it.Explanation
http://localhost:4422/attachments/1b4956bf4d77aa6ddd3c3d68272dd6683cb7cc37/store/limit/160/320/b81d4a3cc45d2ae38b601cdd6587ac40087ab89f4b2750fbefb1d5832f0e/thumb.png
)Plug.Conn.send_file/3
initiates sending the temp file router.ex:169 and cowboy delegates thesendfile
call to the kernel which begins to actually send the data to the client.Exfile.Tempfile
deletes the temp file tempfile:103Steps to reproduce
limit
)transfer closed with n bytes remaining to read
(in case ofcurl
).Possible solutions
Plug.Conn.send_resp/3
calls to send the binary data from elixir itself.I don't particularly like any of them, but I'll think about better workarounds later.