yaws
yaws copied to clipboard
added max chunk check on recv
this fix allows yaws to receive data over 64MB in size. open an erlang shell, start a tcp listener, send 256M + 1B and connect to it with:
spawn(fun() ->
{ok,LS} = gen_tcp:listen(3456,[{reuseaddr, true}, {active, false}, binary]),
{ok,SS} = gen_tcp:accept(LS),
gen_tcp:send(SS,crypto:strong_rand_bytes((4 * 64 * 1024 * 1024) + 1)),
receive stop -> ok end
end).
{ok,RS} = gen_tcp:connect("localhost",3456,[{reuseaddr, true}, {active, false}, binary]).
then on the receive side note that this can only be consumed in chunks of 64MB or less:
gen_tcp:recv(SS, (64 * 1024 * 1024) + 0, 1000).
gen_tcp:recv(SS, (64 * 1024 * 1024) + 1, 1000).
gen_tcp:recv(RS, (64 * 1024 * 1024) + 0, 1000).
gen_tcp:recv(RS, (64 * 1024 * 1024) + 1, 1000).
gen_tcp:recv(RS, (64 * 1024 * 1024) + 0, 1000).
gen_tcp:recv(RS, (64 * 1024 * 1024) + 1, 1000).
gen_tcp:recv(RS, (64 * 1024 * 1024) + 0, 1000).
gen_tcp:recv(RS, (64 * 1024 * 1024) + 1, 1000).
gen_tcp:recv(RS, 1, 1000).
in our application all uploads of files greater than 64MB fail with enomem in the same way as demonstrated here. this change works in our application at least.
Thanks for your PR!
Please add a test for the new behaviour.
Please write a longer commit message describing the change. (Parts of the PR's description are good candidates of info describing the reason and method for the change.)