Re: sshd doesn't disconnect for 30+ minutes after the TCP connection is closed ungracefully

From: Mike Karels <mike_at_karels.net>
Date: Wed, 01 Mar 2023 13:03:27 UTC
On 1 Mar 2023, at 5:36, Michael Gmelin wrote:

>> On 1. Mar 2023, at 11:35, Yuri <yuri@freebsd.org> wrote:
>>
>> Windows system connects to FreeBSD through ssh and then this connection dies because of WiFi or VPN issues.
>>
>> FreeBSD still has the sshd process alive for this connection for 30+ minutes.
>>
>> TCP keepalive is enabled on the FreeBSD host:
>>
>> $ sysctl net.inet.tcp.always_keepalive
>> net.inet.tcp.always_keepalive: 1
>>
>> Shouldn't TCP keepalive kill this sshd process after 3-4 minutes because this connection isn't alive?
>>
>
> Keepalives start after net.inet.tcp.keepidle milliseconds (2h by default).

When this happens to me, I generally log into the server again and use write(1)
to send a message to that tty (a newline will do).  That probes the connection
and causes a reset, and the session gets cleaned up.  I use a longer keepidle
value for other reasons.

		Mike