google / gvisor

Application Kernel for Containers
https://gvisor.dev
Apache License 2.0
15.63k stars 1.29k forks source link

TCP CurrentEstablished counter decrements soon after transition from Established state #1579

Closed iyermi closed 4 years ago

iyermi commented 4 years ago

With the recent changes, I see that TCP CurrentEstablished counter decrements soon after transition from Established state. This is problematic because: (1) The TCP connection can still be active (behave as established) and be receiving data even after transition from StateEstablished. (2) With the current behavior, an active TCP connection would not be accounted for by any of the stats up until it transitions to StateClose.

Suggest to decrement this counter only when we transition to StateClose from StateLastAck or StateTimeWait. This was the older behavior. OR we can introduce a new counter to track all active TCP connections (previously established) that are not yet closed.

hbhasker commented 4 years ago

Just to record what was discussed. The new behaviour mirrors linux, I believe the old behaviour was incorrect. eg. Linux behaviour is here https://code.woboq.org/linux/linux/net/ipv4/tcp.c.html#2249 and it matches what is now implemented in Netstack.

I would recommend introducing a separate counter. In terms of TCP, ESTABLISHED is a specific state and this counter is meant to track connections in that state. The shutdown states are considered connected states but not Established.