[erlang-bugs] SSL fails at sending a short message while receiving a big one

Loïc Hoguin essen@REDACTED
Sun Feb 9 11:44:15 CET 2014


Hello,

Here's another test case.

This time we do read the data sent by the client, print it, and then 
send some data ourselves. The client receives nothing. When the shutdown 
call is there, the client receives an {error, closed} immediately. When 
the shutdown call isn't there, the client waits 30 seconds before 
receiving {error, closed}. Which is crazy considering the client has a 
recv timeout of 5 seconds.

Other than that, I also matched the return of the server's ssl:send to 
make sure it returns ok, and I use the binary option because otherwise 
Erlang ran out of memory (sounds excessive for 100MB of data but whatever).

Please see the attached module. Like previous test cases, you need 
erl_make_certs from the SSL test suite.

Without shutdown.

1> c(erl_make_certs).
{ok,erl_make_certs}
2> c(sslbig2).
{ok,sslbig2}
3> sslbig2:server().
<0.68.0>
4> sslbig2:client().
A = <<"some data before a big body">>
byte_size(B) = 100000000
** exception error: no match of right hand side value {error,closed}
      in function  sslbig2:client/0 (sslbig2.erl, line 32)

With shutdown.

5> c(sslbig2).
{ok,sslbig2}
6> sslbig2:server().
7> sslbig2:server().
<0.116.0>
8> sslbig2:client().
A = <<"some data before a big body">>
byte_size(B) = 100000000
** exception error: no match of right hand side value {error,closed}
      in function  sslbig2:client/0 (sslbig2.erl, line 32)
9>

Enjoy!

On 02/08/2014 07:50 PM, Loïc Hoguin wrote:
> Hello,
>
> While investigating a solution for TCP linger issues with Cowboy, I was
> surprised when I saw that the solution that worked perfectly well for
> TCP didn't for SSL.
>
> It *may* be related to what fails in my other "SSL socket gets closed
> abruptly" thread, as both cases send large data. However that other
> thread is a little more crazy (as sending any non-200 response does work
> there, while in this case I never got any response).
>
> Please see a test case attached. It's a simpler simulation of what may
> actually happen with HTTP. First a few small packets (often one) are
> sent for the headers, and then a potentially huge body. The server may
> not want to receive the body, but it always needs to send a response.
> Problem is, if we don't read the body, that response is never sent with
> SSL.
>
> It's interesting to note that incorrect behavior occurs regardless of
> the shutdown call being there. That call is used for the lingering
> solution mentioned above so I tried with and without. In both cases the
> response isn't received by the client. If the shutdown call is there,
> the recv call will eventually say {error, closed} (it may or may not
> take a while, I had both). If the shutdown call isn't there, recv will
> just timeout.
>
> You need erl_make_certs from the SSL test suite for this test case too.
>
> Below output is for R16B02 but the issue also occurs with master updated
> sometimes this week too.
>
> % erl
> Erlang R16B02 (erts-5.10.3) [source] [64-bit] [smp:4:4]
> [async-threads:10] [hipe] [kernel-poll:false]
>
> Eshell V5.10.3  (abort with ^G)
> 1> c(erl_make_certs).
> {ok,erl_make_certs}
> 2> c(sslbig).
> {ok,sslbig}
> 3> "With shutdown write".
> "With shutdown write"
> 4> sslbig:server().
> <0.69.0>
> 5> sslbig:client().
> ** exception error: no match of right hand side value {error,closed}
>       in function  sslbig:client/0 (sslbig.erl, line 29)
> 6> c(sslbig).
> {ok,sslbig}
> 7> "Without shutdown write".
> "Without shutdown write"
> 8> sslbig:server().
> <0.84.0>
> 9> sslbig:client().
> ** exception error: no match of right hand side value {error,timeout}
>       in function  sslbig:client/0 (sslbig.erl, line 29)
> 10>
>
> Enjoy!
>
>
>
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://erlang.org/mailman/listinfo/erlang-bugs
>

-- 
Loïc Hoguin
http://ninenines.eu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sslbig2.erl
Type: text/x-erlang
Size: 896 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20140209/a9e9cbf5/attachment.bin>


More information about the erlang-bugs mailing list