smux icon indicating copy to clipboard operation
smux copied to clipboard

Unnecessary keepalive frames

Open sintanial opened this issue 5 years ago • 4 comments

I think, If data is read from a connection, then there is no point in sending a keepalive frame. It is necessary to send the keepalive frame after some timeout from the last read operation. Because success read means that connection is alive, and keepalive frame in this case unnecessary.

sintanial avatar Feb 19 '20 09:02 sintanial

can you elaborate?

xtaci avatar Feb 19 '20 09:02 xtaci

Currently this code https://github.com/xtaci/smux/blob/master/session.go#L383 send keepalive frame (cmdNOP) every 10 seconds. During intensive data transfer (cmdPSH), keepalive frames(cmdNOP) are not needed. Because the fact of reading data (cmdPSH) already means that the connection is live.

So, I suggest start sending keepalive frames (cmdNOP) after the last successful reading of data.

The simplest solution is replace https://github.com/xtaci/smux/blob/master/session.go#L384 time.Ticker to time.Timer, and after successful reading cdmPSH reset time.Timer (https://golang.org/pkg/time/#Timer.Reset) ;)

sintanial avatar Feb 19 '20 09:02 sintanial

for receiving only connection, it's necessary to send cmdNOP perodically. only 8 bytes in 10 seconds.

xtaci avatar Feb 20 '20 09:02 xtaci

Maybe you are right and this is overkill :)

sintanial avatar May 23 '20 08:05 sintanial