Commit Graph

40 Commits

Author SHA1 Message Date
ginuerzh 37bc81576c fix(tun): prevent leaked goroutines in bidirectional copy on transport failure
transportClient and transportServer each launch two goroutines for
bidirectional copy between the TUN device and the remote connection.
Previously, when one goroutine errored, the function returned
immediately while the sibling goroutine continued running — reading
from and writing to connections that would soon be closed by the
caller's deferred cleanup. In the retry loop of handleClient and
handleServer, stale goroutines accumulated across iterations, racing
with new goroutines for the TUN device and writing to closed pipes.

This caused the "io: read/write on closed pipe" error reported in
go-gost/gost#345, and more importantly, prevented recovery because
subsequent retry iterations operated on a corrupted state.

Fix:
- Derive a per-transport context in transportClient/transportServer
  and check it at the top of each goroutine's loop to allow the
  first-failing goroutine to signal its sibling to exit
- Replace the single-error select with a collectFirstError helper
  that drains both goroutines and includes a timeout guard (5s) to
  prevent deadlock when a goroutine is stuck in a non-cancelable read
- Use a per-iteration context in handleClient for the keepalive
  goroutine so it is properly cancelled when an iteration ends
- Fix handleServer to use errors.Is(err, ErrTun) for consistency
- Fix transportServer's errc buffer from 1 to 2 to prevent a
  goroutine leak when both goroutines error simultaneously
2026-06-20 22:10:09 +08:00
ginuerzh c7d16962ec add service option for plugin 2025-08-29 23:36:31 +08:00
ginuerzh b597467858 add context for conn 2025-08-04 19:29:38 +08:00
ginuerzh 281295d02f fix tun device 2025-07-23 22:44:02 +08:00
ginuerzh e0915affda use fixed buffer size 2025-02-18 17:38:27 +08:00
ginuerzh 2132268780 Bump golang.zx2c4.com/wireguard 2025-02-11 22:13:57 +08:00
ginuerzh 08ad260606 add entrypoint for router handler 2025-02-08 23:07:54 +08:00
ginuerzh 355c72477a add router handler & connector 2025-02-07 15:44:31 +08:00
ginuerzh 8f994ab632 add handle options for sniffer 2024-10-10 22:49:56 +08:00
ginuerzh 69455ace9d add handler recorder 2024-09-14 23:21:25 +08:00
ginuerzh c1d0887a9b add port range support for service 2024-07-08 22:38:21 +08:00
ginuerzh 332a3a1cd0 add p2p option for tun handler 2024-04-26 20:56:56 +08:00
ginuerzh 74639e9c4e add router component 2023-11-19 14:23:21 +08:00
ginuerzh 9584bdbf4c rm tunnel from relay 2023-11-14 22:35:46 +08:00
ginuerzh d7b7ac6357 add range port support for forwarder node 2023-11-14 19:41:57 +08:00
ginuerzh cc4310106b fix race condition 2023-10-19 23:47:47 +08:00
ginuerzh 61f1f05339 fix panic in tun handler 2023-10-08 22:04:36 +08:00
ginuerzh ea585fc25d add reload and plugin support for hop 2023-09-28 21:04:15 +08:00
ginuerzh 1760151500 add HTTP plugin 2023-09-20 22:56:43 +08:00
ginuerzh 674a70cd23 add client ID for plugin service 2023-09-19 22:31:37 +08:00
ginuerzh 32c8188351 add plugin system 2023-04-18 20:52:56 +08:00
ginuerzh bb106e2d89 fix dtls connection 2022-12-23 18:56:58 +08:00
ginuerzh fb29d5c80e tun: support multiple IPs 2022-12-22 17:44:30 +08:00
ginuerzh bcfff22669 don't resolve server addr for tun handler 2022-11-25 18:14:47 +08:00
ginuerzh 81b6efc9b8 do not recreate tun device when connecting to server failed 2022-11-11 20:53:34 +08:00
ginuerzh 05ddda70e3 update tap 2022-11-04 18:48:28 +08:00
ginuerzh 669e80b780 add auth for tun 2022-10-20 21:08:26 +08:00
ginuerzh 1a1c038fd7 update chain route 2022-09-20 11:48:51 +08:00
ginuerzh a04c8b45f3 update selector 2022-09-04 13:24:32 +08:00
ginuerzh 00f7fa2997 add weight for selector 2022-09-02 17:23:59 +08:00
ginuerzh 09dbdbb03c add backup filter 2022-09-02 11:52:44 +08:00
ginuerzh bdd239fb09 add list support for auther, admission and bypass 2022-08-23 21:49:49 +08:00
ginuerzh fe6554d8a3 add keepalive for tun 2022-08-22 22:14:09 +08:00
ginuerzh ca414f655d update tun handler 2022-08-21 13:54:52 +08:00
ginuerzh 4c1da3e4d4 update tun/tap 2022-08-18 14:50:13 +08:00
ginuerzh f3f3acd4e1 more fine-grained log level 2022-08-18 11:34:57 +08:00
ginuerzh a3346ad246 add pkgs from core 2022-04-04 12:44:35 +08:00
ginuerzh 36947bcbd9 fix imports 2022-03-16 20:06:34 +08:00
ginuerzh 073ad80ce4 remove unnecessary conn 2022-03-15 15:45:22 +08:00
ginuerzh 9397cb5351 initial commit 2022-03-14 20:27:14 +08:00