#1789 net.http.files: Double close of file handle in chunked mode with opportunistic writes
Reporter
Zash
Owner
Nobody
Created
Updated
Stars
★ (1)
Tags
Priority-Medium
Status-Fixed
Milestone-0.12
Type-Defect
Zash
on
What steps will reproduce the problem?
Enable opportunistic writes and serve a file handle of unknown size over http.
```lua
local site_archive = require"zip".open("site.zip");
module:depends("http");
module:provides("http", {
route = {
["GET /*"] = function(event, path)
local file = site_archive:open(path);
return event.response:send_file(file);
end;
};
});
```
What is the expected output?
Should Work
What do you see instead?
error Closing due to error calling ondrain: ./net/http/server.lua:384: attempt to use a closed zip file
stack traceback:
[C]: in method 'close'
./net/http/server.lua:384: in field '_send_more'
./net/http/server.lua:170: in function <./net/http/server.lua:167>
[C]: in function 'util.xpcall.xpcall'
./net/server_epoll.lua:240: in function <./net/server_epoll.lua:226>
(...tail calls...)
./net/server_epoll.lua:517: in method 'onwritable'
./net/server_epoll.lua:1047: in function 'net.server.loop'
[C]: in function 'util.xpcall.xpcall'
./prosody:78: in local 'loop'
./prosody:83: in main chunk
[C]: in ?
What version of the product are you using? On what operating system?
First noticed on 0c3184378032
Reproducible on 0.12.2
Please provide any additional information below.
This happens because the lack of declared file size triggers chunked transfer and sending chunk headers invokes further opportunistic writes via ondrain, such resulting in the file being closed twice, triggering the above error.
What steps will reproduce the problem? Enable opportunistic writes and serve a file handle of unknown size over http. ```lua local site_archive = require"zip".open("site.zip"); module:depends("http"); module:provides("http", { route = { ["GET /*"] = function(event, path) local file = site_archive:open(path); return event.response:send_file(file); end; }; }); ``` What is the expected output? Should Work What do you see instead? error Closing due to error calling ondrain: ./net/http/server.lua:384: attempt to use a closed zip file stack traceback: [C]: in method 'close' ./net/http/server.lua:384: in field '_send_more' ./net/http/server.lua:170: in function <./net/http/server.lua:167> [C]: in function 'util.xpcall.xpcall' ./net/server_epoll.lua:240: in function <./net/server_epoll.lua:226> (...tail calls...) ./net/server_epoll.lua:517: in method 'onwritable' ./net/server_epoll.lua:1047: in function 'net.server.loop' [C]: in function 'util.xpcall.xpcall' ./prosody:78: in local 'loop' ./prosody:83: in main chunk [C]: in ? What version of the product are you using? On what operating system? First noticed on 0c3184378032 Reproducible on 0.12.2 Please provide any additional information below. This happens because the lack of declared file size triggers chunked transfer and sending chunk headers invokes further opportunistic writes via ondrain, such resulting in the file being closed twice, triggering the above error.
Fixed in https://hg.prosody.im/trunk/rev/1cdaf21584da
Changes