You can close any idle connection.
But when a TCP socket is unused for a while the congestion window is reset, 
and next time it is used,
it will be in slow start mode. So a recently used connection is likely to 
have a larger window size, and allow
faster transmission, than one which has been idle for a long time. 
So when you are deciding which idle connection to close, it is reasonable 
to close the one which has been idle
for longest.

On Tuesday, 26 April 2022 at 13:36:17 UTC+1 chenc...@gmail.com wrote:

> I read golang's source code recently, and find a place that doesn't make 
> sence.
>
> ```
>
> if t.MaxIdleConns != 0 && t.idleLRU.len() > t.MaxIdleConns { 
>
>       oldest := t.idleLRU.removeOldest() 
>
>       oldest.close(errTooManyIdle) 
>
>       t.removeIdleConnLocked(oldest) 
>
> }
>
> ```
>
> the code is here : 
> https://github.com/golang/go/blob/96c8cc7fea94dca8c9e23d9653157e960f2ff472/src/net/http/transport.go#L984-L988
>
> question: 
>
> when idleConn's length > t.MaxIdleConns, why not close the conn directly 
> instead of putting the conn into a new list. and remove the oldest conn in 
> the list. As I understand it, it's simple to close the redundant 
> connection, and it turns out to be corrent.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/a07dd7c1-baff-47ae-8457-d18cd0b40973n%40googlegroups.com.

Reply via email to