I found my https server (powered by mochiweb) blocked and rejected new
connections after running for days. After capturing a coredump and
analyzing it, I found all 16 acceptor processes were blocked at
ssl:ssl_accept (mochiweb_socket:accept/1).
This problem can be reproduced like this:
wei@t-mingsong:~$ irb
irb(main):001:0> require 'socket'
=> true
irb(main):002:0> sockets = (1..16).map{|i| TCPSocket.open('127.0.0.1',
8080) }
=> [#<TCPSocket:0x7f9af3508a08>, ... , #<TCPSocket:0x7f9af3507388>]
At this time, all acceptors're blocked and hangs over incoming wget
request forever.
wei@t-mingsong:~$ wget https://127.0.0.1:8080 --no-check-certificate
--2011-12-12 16:29:52-- https://127.0.0.1:8080/
Connecting to 127.0.0.1:8080...
Here is my patch,
https://github.com/weicao/mochiweb/compare/fix_acceptor_blocked_in_ssl
https://github.com/weicao/mochiweb/compare/fix_acceptor_blocked_in_ssl.patch
I can confirm this problem. I'm to blame for this one since I submitted
the initial ssl patch.
> Here is my patch,
>
> https://github.com/weicao/mochiweb/compare/fix_acceptor_blocked_in_ssl
> https://github.com/weicao/mochiweb/compare/fix_acceptor_blocked_in_ssl.patch
I would write the patch slightly differently (see attached) for the
following reasons:
1. The way you've added in the extra call to mochiweb_socket:after_accept/1
will result in all SSL errors getting ignored instead of being logged.
2. The purpose behind the mochiweb_socket module was to be able to treat
SSL and non-SSL sockets in the same way. The extra call to
mochiweb_socket:after_accept/1 only applies to SSL sockets, so
it goes against the spirit of the module in my opinion.
At a guess, I would say that Bob might be more likely to accept your patch
if you change it to being more like the one I've attached. Full credit to
you though Wei!
Thanks,
Rory
On Mon, Dec 12, 2011 at 12:54:19AM -0800, Wei wrote:I can confirm this problem. I'm to blame for this one since I submitted
> I found my https server (powered by mochiweb) blocked and rejected new
> connections after running for days. After capturing a coredump and
> analyzing it, I found all 16 acceptor processes were blocked at
> ssl:ssl_accept (mochiweb_socket:accept/1).
>
the initial ssl patch.
I would write the patch slightly differently (see attached) for the
> Here is my patch,
>
> https://github.com/weicao/mochiweb/compare/fix_acceptor_blocked_in_ssl
> https://github.com/weicao/mochiweb/compare/fix_acceptor_blocked_in_ssl.patch
following reasons:
1. The way you've added in the extra call to mochiweb_socket:after_accept/1
will result in all SSL errors getting ignored instead of being logged
2. The purpose behind the mochiweb_socket module was to be able to treat
SSL and non-SSL sockets in the same way. The extra call to
mochiweb_socket:after_accept/1 only applies to SSL sockets, so
it goes against the spirit of the module in my opinion.
At a guess, I would say that Bob might be more likely to accept your patch
if you change it to being more like the one I've attached. Full credit to
you though Wei!
Thanks,
Rory
--
You received this message because you are subscribed to the Google Groups "MochiWeb" group.
To post to this group, send email to moch...@googlegroups.com.
To unsubscribe from this group, send email to mochiweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mochiweb?hl=en.
Was really just pointing out that up till now when ssl:ssl_accept/1
returned {error, reason()} the reason() part would be logged if it
wasn't 'closed', 'timeout' or 'esslaccept'.
>
> For SSL acceptor, the most efficient actions should be:
> 1. listen until a new connection in
> 2. send a message to notify mochiweb_socket_server to create a new acceptor
> 3. finish the SSL handshake
> 4. go to the main loop
>
> Https server can avoid be blocked by idle connections only in this way, the
> key point
> is we cannot wait to create new acceptor until handshake finishes.
>
Yep, you're totally right. My mistake.
Nice fix! :-)