-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The closeConnection method for tls connections should not be called multiple times #225
Comments
It was me who introduced the The bug occurs with |
Thanks for reviewing @Yuras. If you feel comfortable with the proposed solution, let's go with it, I'll be happy to review/merge a PR. |
Connection could be closed via explicit `connectionClose` call or via finalizer attached to it. Both should check status to prevent writing to or reading from closed connection. See snoyberg#225
Connection could be closed via explicit `connectionClose` call or via finalizer attached to it. Both should check status to prevent writing to or reading from closed connection. See snoyberg#225
Connection could be closed via explicit `connectionClose` call or via finalizer attached to it. Both should check status to prevent writing to or reading from closed connection. See snoyberg#225
Connection could be closed via explicit `connectionClose` call or via finalizer attached to it. Both should check status to prevent writing to or reading from closed connection. See snoyberg#225
Connection could be closed via explicit `connectionClose` call or via finalizer attached to it. Both should check status to prevent writing to or reading from closed connection. See snoyberg#225
Closing based on feedback so far, if the bug still exists, please reopen. |
Connection could be closed via explicit `connectionClose` call or via finalizer attached to it. Both should check status to prevent writing to or reading from closed connection. See #225
thanks @cdepillabout |
Without this, using stack upload with digest support triggers snoyberg/http-client#225. This change could arguably be made in a separate PR, but including with digest support since it would be a very dangerous idea to not bump the http-client version.
Without this, using stack upload with digest support triggers snoyberg/http-client#225. This change could arguably be made in a separate PR, but including with digest support since it would be a very dangerous idea to not bump the http-client version.
In my application I make two successive connections to Facebook's Graph API using
http-conduit
. I'm experiencing a bug when making two calls one after the other. The second call is throwing a TLS error in the middle of the conversation for some reason. I think I've figured out why it is happening, but the explantion is pretty long, so please bear with me.http-conduit
is usinghttp-client-tls
andhttp-client
.http-client-tls
is using theconnection
library to actually create connections.http-client-tls
'sconvertConnection
function is used to convert aconnection
Network.Connection.Types.Connection
to anhttp-client
Connection
.http-client-tls
'sconvertConnection
function is usingmakeConnection
to create thehttp-client
Connection
.The following is the
convertConnection
function:Note how
makeConnection
'sc
argument is becoming the following:makeConnection
looks like this:Since
istack
's finalizer isc
, andc
is actuallyNetwork.Control.connectionClose conn
,Network.Control.connectionClose
actually ends of getting called twice. Once whenhttp-client
'sconnectionClose
is called, and a second time when istack goes out of scope.Let's look at
Network.Control.connectionClose
:In the case where we are dealing with a tls connection,
TLS.bye
is called beforeTLS.contextClose
is called.TLS.bye
is actually sending a packet on the socket in question.The problem occurs by calling
TLS.bye
twice.Here's what (I believe) is happening in my app:
Network.HTTP.Conduit.http
to make my connection to Facebook's API.makeConnection
is called, setting up everything correctly, and settingistack
's finalizer toNetwork.Connection.connectionClose
.http-client
is nice enough to callconnectionClose
, which in turn callsNetwork.Connection.connectionClose
.Network.Connection.connectionClose
,TLS.bye
is used to send a message to Facebook's servers saying to end the connection. The Socket pointed to from file descriptor number 16 is closed.http
.http-client
starts sending data to Facebook with this new Socket.istack
from (3) goes out of scope, causing its finalizer to fire. Since its finalizer isNetwork.Connection.connectionClose
,TLS.bye
is called again. Normally this wouldn't be a problem, since the socket is already closed, but in (7), a new socket was created which ended up with the same file descriptor. SoTLS.bye
sends a message on the wrong socket.I believe the way to fix this is to make
istack
's finalizer be the entireconnectionClose
function. That way,TLS.bye
is only ever called once:I'm only able to reproduce this bug by using
connection-0.2.6
, specifically the version with this commit whereconnection
uses Sockets instead of Handles by default. Maybe @vincenthz would be able to shed some light on why this is happening?P.S. I would have thought someone else would have run into this bug. I'm somewhat worried that I'm misdiagnosing this bug.
The text was updated successfully, but these errors were encountered: