yaws icon indicating copy to clipboard operation
yaws copied to clipboard

added max chunk check on recv

Open seanmcevoy opened this issue 2 years ago • 1 comments

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.

seanmcevoy avatar Oct 05 '22 12:10 seanmcevoy

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.)

avtobiff avatar Nov 15 '22 12:11 avtobiff