-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Aleth should wait 2 seconds to close socket after sending disconnect to peer #5650
Comments
Hey @halfalicious I am very much interested in solving this issue! |
@twinstar26 Sure thing, it's yours! 😄 |
Hey @halfalicious so, Lines 299 to 310 in c630593
Session::sealAndSend() is calling Session::send() which is calling Session::write() performing async_write(). And to solve this issue we need to sleep the current thread by 2 secs after async_write() has done sending disconnect packet. An easy solution WITHOUT MODIFYING Session::write() might be to keep a check on m_writeQueue (if its empty or not. Empty indicates successful disconnect packet sent) inside of Session::disconnect(). By modifying Session::write():- So which one to go by?? Do you have any other idea?? |
Your call chain is correct (
What would this check look like? How would we continuously execute this check until
We already have an async_write handler in Lines 238 to 256 in 71f9ba6
I think that we can check the write queue in the handler and when it is empty we know that the disconnect has been sent so we can start the deadline timer. I think that you also need to add a check in
Be sure to do this before the call to Additionally, we're going to need to avoid closing the socket immediately after sending the disconnect packet since we want to keep it open for 2 seconds. So, I propose the following additional changes to do this:
After you've made and tested these changes it would also be great if you could create a unit test which validates the new behavior, though we can chat about that when you've finished with your changes 😃 |
Can we, to avoid complications, start the timer from |
Presumably you mean to start the timer in cc @twinstar26 |
Yes, right, I meant |
According to the RLPX handshake spec, one should give clients 2 seconds to disconnect after sending a disconnect packet:
However, Aleth closes the socket immediately (via
Session::drop
). This also means that the disconnect packet may not be sent - this is becauseSession::disconnect
(and all of the functions it calls) is executed on the network thread, whereas theasync_write
may not execute immediately in which case I suspect it will execute afterSession::disconnect
/Session::drop
:aleth/libp2p/Session.cpp
Lines 299 to 310 in c630593
Here's where the actual socket write takes place (in
Session::write
):aleth/libp2p/Session.cpp
Lines 237 to 256 in c630593
The text was updated successfully, but these errors were encountered: