https problem solved.

1 view
Skip to first unread message

Eric Wong

unread,
Jan 13, 2012, 8:15:06 AM1/13/12
to sn...@snapframework.com, Gregory Collins
Hi,

I dived into the source code of snap-server and found the function 'shutdown Bidirectional' to shutdown the SSL connection failed. Then this happened, the code to close the socket never execute. I change the code to 'shutdown Unidirectional' and it's working perfect for me. 
Hope this can help others encountered this problem.

Eric

MightyByte

unread,
Jan 13, 2012, 10:35:02 AM1/13/12
to Eric Wong, sn...@snapframework.com, Gregory Collins
Thanks, that's great. If you submit a pull request on github, it
makes it easier for us to make the change and verify that it solves
your problem, while at the same time making sure that you get credit
for it.

Gregory Collins

unread,
Jan 14, 2012, 4:00:28 AM1/14/12
to Eric Wong, sn...@snapframework.com
Hi Eric,

Thanks for looking into this. After having looked at the docs, it's clear that unidirectional shutdown is what we want here. I've pushed the appropriate fix to the github master version of snap-server -- could you please try it out to see if it fixes your problem?

G
-- 
Gregory Collins <gr...@gregorycollins.net>

Eric Wong

unread,
Jan 15, 2012, 6:40:34 AM1/15/12
to Gregory Collins, sn...@snapframework.com
Hi,

Just changed to use unidirectional shutdown does not solve the problem completely. There will still be some connections leaked in CLOSE_WAIT state. I finally find the reason. In the createSession function in TLS.hs, the function 'accept ssl' can fail because the underlining socket connection may have been terminated. If this happens, the createSession function won't return a NetworkSession, it will raise an exception, and the code in the bracket function in SimpleBackend.hs won't execute and the socket won't be closed! 

The simplest solution is changing
    accept ssl
to:
    accept ssl `catch` \(_::SomeException) -> return()

So it will create an valid NetworkSession even the socket connection has been terminated. Then the handler will raise another exception and the code in the bracket function will be executed to finally close the socket.
This is not the best solution in performance, because it has the handler read or write to the socket even it already knows the connection is terminated, and only close the socket when the second exception is raised.
But it's simple and it works.

Eric

Gregory Collins

unread,
Jan 16, 2012, 4:15:35 PM1/16/12
to Eric Wong, sn...@snapframework.com
2012/1/15 Eric Wong <wsy...@gmail.com>

Hi,

Just changed to use unidirectional shutdown does not solve the problem completely. There will still be some connections leaked in CLOSE_WAIT state. I finally find the reason. In the createSession function in TLS.hs, the function 'accept ssl' can fail because the underlining socket connection may have been terminated. If this happens, the createSession function won't return a NetworkSession, it will raise an exception, and the code in the bracket function in SimpleBackend.hs won't execute and the socket won't be closed! 

The simplest solution is changing
    accept ssl
to:
    accept ssl `catch` \(_::SomeException) -> return()

Eric Wong

unread,
Jan 16, 2012, 8:24:29 PM1/16/12
to Gregory Collins, sn...@snapframework.com
Yes, it's great.
Reply all
Reply to author
Forward
0 new messages