Skip to content

Comments

TUN inbound: Close connection when handling is done#5531

Merged
RPRX merged 1 commit intoXTLS:mainfrom
Owersun:tun-close-connection
Jan 13, 2026
Merged

TUN inbound: Close connection when handling is done#5531
RPRX merged 1 commit intoXTLS:mainfrom
Owersun:tun-close-connection

Conversation

@Owersun
Copy link
Collaborator

@Owersun Owersun commented Jan 13, 2026

dispatcher.DispatchLink calls conn.Close() (or rather common.Interrupt()) on incoming connection only if error occurs.
conn.Close() is not called in case of successful handling (connection finishes or completes by outbound policy idle timeout), when DispatchLink return with no error and HandleConnection function just ends.
This breaks lifecycle handling, and leave connections (both TCP/UDP) dangling in gVisor while already closed from upstream side.
Add defer conn.Close(), always signalling handled connection to close to the input (tun) side, send finish packets (TCP) and cleanup handling (UDP).

@RPRX
Copy link
Member

RPRX commented Jan 13, 2026

确定没问题的话我就先合了

@RPRX
Copy link
Member

RPRX commented Jan 13, 2026

幸好还没发版,躲过一次背刺

@Owersun
Copy link
Collaborator Author

Owersun commented Jan 13, 2026

yeah, sorry for that. we did so many changes so quick, that it's hard to properly do long testing of it. things slipped. when there are many connections open, if I look at prof there is like 500 more coroutines and then 300 less in few minutes. which looks "fine", but actually wasn't.
I spend yesterday and today testing and found out that there is no .Close() call on sucessfull finish, and it is required for proper lifecycle (otherwise gVisor don't know that connection is no longer open)
If you wait with the release one more day, so I'll monitor the situation with this change, see how prof performs, how many are connections there and how my devices perform - that would be perfect

@RPRX
Copy link
Member

RPRX commented Jan 13, 2026

没事,今天先发版让大家测测吧,隔几天再发一版也是常态

@RPRX RPRX changed the title Proxy: TUN: Close connection when handling is done TUN inbound: Close connection when handling is done Jan 13, 2026
@RPRX RPRX merged commit 21c2692 into XTLS:main Jan 13, 2026
39 checks passed
@Owersun Owersun deleted the tun-close-connection branch January 13, 2026 16:42
@RPRX
Copy link
Member

RPRX commented Jan 17, 2026

@Owersun #5525 (comment) 有进展吗

@Owersun
Copy link
Collaborator Author

Owersun commented Jan 17, 2026

I was monitoring the implementation that was release for whole last week.
After this change it all look proper and good, this change was final cherry on the top, and the implementation is proper after that, as designed. No crashes, no issues.
I'll start looking at how to implement simple routing next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants