heiher / hev-socks5-server

A high-performance socks5 server for Unix (Linux/Android/BSD/macOS)
MIT License
185 stars 33 forks source link

UDP timeout not triggering #44

Closed vavrecan closed 5 months ago

vavrecan commented 5 months ago

Seems like UDP is not closing -

[2024-01-21 18:13:47] [I] 0x77e10328 io timeout [2024-01-21 18:13:47] [D] 0x77e10328 socks5 udp fwd b [2024-01-21 18:13:47] [I] 0x77e14068 io timeout [2024-01-21 18:13:47] [D] 0x77e14068 socks5 udp fwd b [2024-01-21 18:13:47] [I] 0x77e14718 io timeout [2024-01-21 18:13:47] [D] 0x77e14718 socks5 udp fwd b [2024-01-21 18:13:47] [I] 0x77e14458 io timeout [2024-01-21 18:13:47] [D] 0x77e14458 socks5 udp fwd b [2024-01-21 18:14:47] [I] 0x77e10328 io timeout [2024-01-21 18:14:47] [D] 0x77e10328 socks5 udp fwd b [2024-01-21 18:14:47] [I] 0x77e14068 io timeout [2024-01-21 18:14:47] [D] 0x77e14068 socks5 udp fwd b [2024-01-21 18:14:47] [I] 0x77e14718 io timeout [2024-01-21 18:14:47] [D] 0x77e14718 socks5 udp fwd b [2024-01-21 18:14:47] [I] 0x77e14458 io timeout [2024-01-21 18:14:47] [D] 0x77e14458 socks5 udp fwd b [2024-01-21 18:15:47] [I] 0x77e10328 io timeout [2024-01-21 18:15:47] [D] 0x77e10328 socks5 udp fwd b [2024-01-21 18:15:47] [I] 0x77e14068 io timeout [2024-01-21 18:15:47] [D] 0x77e14068 socks5 udp fwd b [2024-01-21 18:15:47] [I] 0x77e14718 io timeout [2024-01-21 18:15:47] [D] 0x77e14718 socks5 udp fwd b [2024-01-21 18:15:47] [I] 0x77e14458 io timeout [2024-01-21 18:15:47] [D] 0x77e14458 socks5 udp fwd b

despite timeout is triggering. i think the problem can be in some weird state and following condition

        splice->alive &= ~HEV_SOCKS5_UDP_ALIVE_B;
        if (splice->alive && hev_socks5_get_timeout (HEV_SOCKS5 (self)))
            return 0;

in hev-socks5-udp.c

once I terminate it manually with ctrl^c it will clean up correctly and destruct: ^C [2024-01-21 18:18:30] [D] 0x77e16040 works worker stop [2024-01-21 18:18:30] [D] 0x77e14068 socks5 session terminate [2024-01-21 18:18:30] [D] 0x77e14718 socks5 session terminate [2024-01-21 18:18:30] [D] 0x77e10328 socks5 session terminate [2024-01-21 18:18:30] [D] 0x77e14458 socks5 session terminate [2024-01-21 18:18:30] [I] 0x77e14068 io timeout [2024-01-21 18:18:30] [D] 0x77e14068 socks5 udp fwd b recv [2024-01-21 18:18:30] [D] 0x77e14068 socks5 session destruct [2024-01-21 18:18:30] [D] 0x77e14068 socks5 server destruct [2024-01-21 18:18:30] [D] 0x77e14068 socks5 destruct [2024-01-21 18:18:30] [I] 0x77e14718 io timeout [2024-01-21 18:18:30] [D] 0x77e14718 socks5 udp fwd b recv [2024-01-21 18:18:30] [D] 0x77e14718 socks5 session destruct [2024-01-21 18:18:30] [D] 0x77e14718 socks5 server destruct [2024-01-21 18:18:30] [D] 0x77e14718 socks5 destruct [2024-01-21 18:18:30] [I] 0x77e10328 io timeout [2024-01-21 18:18:30] [D] 0x77e10328 socks5 udp fwd b recv [2024-01-21 18:18:30] [D] 0x77e10328 socks5 session destruct [2024-01-21 18:18:30] [D] 0x77e10328 socks5 server destruct [2024-01-21 18:18:30] [D] 0x77e10328 socks5 destruct [2024-01-21 18:18:30] [I] 0x77e14458 io timeout [2024-01-21 18:18:30] [D] 0x77e14458 socks5 udp fwd b recv [2024-01-21 18:18:30] [D] 0x77e14458 socks5 session destruct [2024-01-21 18:18:30] [D] 0x77e14458 socks5 server destruct [2024-01-21 18:18:30] [D] 0x77e14458 socks5 destruct [2024-01-21 18:18:30] [D] 0x77e16040 works worker destroy [2024-01-21 18:18:30] [D] 0x77e15e20 socks5 authenticator destruct [2024-01-21 18:18:30] [D] 0x77e160a0 socks5 user mark destruct [2024-01-21 18:18:30] [D] 0x77e160a0 socks5 user destruct [2024-01-21 18:18:30] [D] 0x77e16070 socks5 user mark destruct [2024-01-21 18:18:30] [D] 0x77e16070 socks5 user destruct

vavrecan commented 5 months ago

is when using udp over tcp

vavrecan commented 5 months ago

This is how i patched this: https://github.com/vavrecan/hev-socks5-core/commit/d90eab968fd73215594703eb8b633788434f063d I think there is scenario when TCP connection is break, first loop of splicer exists and other one is blocked because of that.

heiher commented 5 months ago

Fixed: https://github.com/heiher/hev-socks5-core/commit/c7b485dbc32f7b677342a073ecf3edfa887f4dd7

Thanks~