kernel tcp sockets stuck in FIN_WAIT1 after call tcp_close
Subsystems (3)
Quoted 18 lines
-----邮件原件-----
发件人: Kuniyuki Iwashima <[email protected]>
发送时间: 2024年11月14日 2:56
收件人: mengkanglai <[email protected]>
抄送: [email protected]; [email protected]; [email protected]; Fengtao (fengtao, Euler) <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Yanan (Euler) <[email protected]>; [email protected] 主题: Re: kernel tcp sockets stuck inFIN_WAIT1after calltcp_closeFrom: mengkanglai <[email protected]>
Date: Wed, 13 Nov 2024 12:40:34 +0000Quoted 6 lines
Hello, Eric:
Commit151c9c724d05(tcp: properly terminate timers for kernel sockets) introduceinet_csk_clear_xmit_timers_syncintcp_close. For kernel sockets it does not holdsk->sk_net_refcnt, if this is kernel tcp socket it will calltcp_send_finin__tcp_closeto send FIN packet to remotes server,Just curious which subsystem the kernel socket is created by.
Quoted 13 lines
Recently, CIFS and sunrpc are (being) converted to hold net refcnt.
CIFS: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ef7134c7fc48e1441b398e55a862232868a6f0a7
sunrpc: https://lore.kernel.org/netdev/[email protected]/I remember RDS's listener does not hold refcnt but other client sockets (SMC, RDS, MPTCP, CIFS, sunrpc) do.
I think all TCP kernel sockets should hold netns refcnt except for one created at
pernet_operations.init()hook like RDS.Quoted 4 lines
if this fin packet lost due to network faults, tcp should retransmit this fin packet, but
tcp_timerstopped byinet_csk_clear_xmit_timers_sync. tcp sockets state will stuck inFIN_WAIT1and never go away. I think it's not right.
I found this problem when testing nfs. sunrpc: https://lore.kernel.org/netdev/[email protected]/ will solve this problem.
I agree with that all TCP kernel sockets should hold netns refcnt.
However, for kernel tcp sockets created by other kernel modules through sock_create_kern or sk_alloc(kern=0), it means that they must now hold sk_net_refcnf, otherwise fin will only be sent once and will not be retransmitted when the socket is released.But other use tcp modules may not be aware of hold sk_net_refcnt. should we add a check in tcp_close?
---
net/ipv4/tcp.c +1 -1
@@ -2804,7 +2804,7 @@ void tcp_close(struct sock *sk, long timeout)lock_sock (sk);__tcp_close (sk, timeout);release_sock (sk); -if (!sk->sk_net_refcnt) +if (sk->net != &init_net && !sk->sk_net_refcnt)inet_csk_clear_xmit_timers_sync (sk);sock_put (sk); }
From: mengkanglai <[email protected]>
Date: Tue, 19 Nov 2024 08:38:26 +0000
Quoted 27 lines
Quoted 12 lines
From: mengkanglai <[email protected]>
Date: Wed, 13 Nov 2024 12:40:34 +0000Quoted 6 lines
Hello, Eric:
Commit151c9c724d05(tcp: properly terminate timers for kernel sockets) introduceinet_csk_clear_xmit_timers_syncintcp_close. For kernel sockets it does not holdsk->sk_net_refcnt, if this is kernel tcp socket it will calltcp_send_finin__tcp_closeto send FIN packet to remotes server,Just curious which subsystem the kernel socket is created by.
Quoted 13 lines
Recently, CIFS and sunrpc are (being) converted to hold net refcnt.
CIFS: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ef7134c7fc48e1441b398e55a862232868a6f0a7
sunrpc: https://lore.kernel.org/netdev/[email protected]/I remember RDS's listener does not hold refcnt but other client sockets (SMC, RDS, MPTCP, CIFS, sunrpc) do.
I think all TCP kernel sockets should hold netns refcnt except for one created at
pernet_operations.init()hook like RDS.Quoted 4 lines
if this fin packet lost due to network faults, tcp should retransmit this fin packet, but
tcp_timerstopped byinet_csk_clear_xmit_timers_sync. tcp sockets state will stuck inFIN_WAIT1and never go away. I think it's not right.
Quoted 4 lines
I found this problem when testing nfs. sunrpc: https://lore.kernel.org/netdev/[email protected]/ will solve this problem. I agree with that all TCP kernel sockets should hold netns refcnt.
However, for kernel tcp sockets created by other kernel modules throughsock_create_kernorsk_alloc(kern=0),
In the next cycle, I'll rename sock_create_kern() to sock_create_net_noref() and add sock_create_net() so that out-of-tree module will fail to build and such users will notice sock_create_net_noref() would trigger an issue.
https://github.com/q2ven/linux/commits/427_2
Quoted 4 lines
it means that they must now hold
sk_net_refcnf, otherwise fin will only be sent once and will not be retransmitted when the socket is released.But other use tcp modules may not be aware of holdsk_net_refcnt. should we add a check in tcp_close?
The check doesn't fix the issue for in-netns users.
I'd rather print the allocator and change it to use sock_create_net() instead.
---8<---
net/ipv4/tcp.c +5 -1
@@ -3220,8 +3220,12 @@ void tcp_close(struct sock *sk, long timeout)lock_sock (sk);__tcp_close (sk, timeout);release_sock (sk); + +#ifdef CONFIG_NET_NS_REFCNT_TRACKER if (!sk->sk_net_refcnt) -inet_csk_clear_xmit_timers_sync (sk); +stack_depot_print (sk->ns_tracker); +#endif +sock_put (sk); }EXPORT_SYMBOL (tcp_close);
---8<---
Quoted 15 lines
---
net/ipv4/tcp.c +1
-1@@ -2804,7 +2804,7 @@ void tcp_close(struct sock *sk, long timeout)lock_sock (sk);__tcp_close (sk, timeout);release_sock (sk); -if (!sk->sk_net_refcnt) +if (sk->net != &init_net && !sk->sk_net_refcnt)inet_csk_clear_xmit_timers_sync (sk);sock_put (sk); }