Skip to content

UDP-dispatcher: fix activity timer cause connection disconnected every minutes#4897

Closed
patterniha wants to merge 1 commit intoXTLS:mainfrom
patterniha:fix-dispatcher-2
Closed

UDP-dispatcher: fix activity timer cause connection disconnected every minutes#4897
patterniha wants to merge 1 commit intoXTLS:mainfrom
patterniha:fix-dispatcher-2

Conversation

@patterniha
Copy link
Collaborator

@patterniha patterniha commented Jul 15, 2025

when target-connection is udp, after the first disconnection between xray-client and xray-server, the connection between xray-client and xray-server is disconnected every minute, Let's do the following reproduction-method to understand better:

  1. you need python with PySocks package(pip install PySocks)

  2. run xray-client and xray-server both on one PC

  3. run echo-server.py with python(python echo-server.py)
    this is a simple udp echo server

  4. run echo-socks-client.py with python
    this is simple udp echo client that use socks5 protocol to connect

    echo-socks-client.py <-> xray-client <-> xray-server <-> echo-server.py

  5. after a few seconds, terminate xray-server and then re-run xray-server (to disconnect connection between client-xray and server-xray, and re-established again)

  6. sniff connection between xray-client and xray-server (loopback-adapter-port-1234)

Then you see that every minute the connection between xray-client and xray-server is disconnected and then re-established.(while the connection is not idle and should not be closed)

Screenshot 2025-07-15 032342

///

this is important issue, that causes us to have frequent disconnections between xray-client and xray-server(after first disconnecting with any reason)

Also, because we bind a new port(freedom-udp) in server-side every time, it can cause a lot of problems.

///

Why is this happening?

This is because of this wrong code:

removeRay := func() {
cancel()
v.RemoveRay()
}
timer := signal.CancelAfterInactivity(ctx, removeRay, time.Minute)

After previous-connection is closed, it's timer remains active, and after a minute it run v.RemoveRay() and RemoveRay close v.conn, but now v.conn is our new connection which is active and should not be closed !!!

And this process repeating...

///

other refine:

in worker.go it is better to cancel ctx after udpConn is closed

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