Bugfix: HandshakeSession emitting the signal handshakingFailed() twice

I found and fixed a bug in HandshakeSession. It sometimes happened that failed() was called twice for the same HandshakeSession object, for example when the remote node rejected us and directly closed the connection. Calling failed() twice resulted in emitting handshakingFailed() twice, which lead to Handshaker deleting the session object twice!

As of this patch, if handshaking fails due to some error, then we close the connection and defer emitting handshakingFailed() until the connection gets actually closed. That would have happened when we enter the slot connectionClosed(). From there the signal handshakingFailed() will be emitted unless we have already emitted handshakingCompleted() – possible if events get queued by Qt in a specific order. If that happened, then the Connection will not be in ConnectedState when creating a new PacketSession object. In this case the new PacketSession should directly be closed (that’s on my TODO list now).

Regards,

Peter

Would you like to post a relpy?


This post starts a thread.
Follow-ups:
Re: Bugfix: HandshakeSession emitting the signal handshakingFailed() twice
In the last HandshakeSession related patch I fixed a bug that caused failed() to be called twice. I also added a Q_ASSERT in the very beginning of failed() that asserts (more...)