erebe / wstunnel

Tunnel all your traffic over Websocket or HTTP2 - Bypass firewalls/DPI - Static binary available
Other
3.16k stars 287 forks source link

Reverse tunnel port listening lost #262

Closed debin-ge closed 1 week ago

debin-ge commented 1 week ago

Describe the bug I can quickly achieve reverse tunnel communication via command. But after about 30 minutes, the server stopped Listening the service, but there was no error message. I found that the server is no longer listening to port 10000. This feels weird to me and prevents me from using it.

To Reproduce wstunnel server wss://0.0.0.0:33073

wstunnel client -R 'socks5://0.0.0.0:10000' wss://139.9.89.206:33073

Screenshots Server: image

Clinet: image

Desktop (please complete the following information):

What do I need to do to maintain tunnel service? Or to troubleshoot the problem

roja commented 1 week ago

I have the same experience. Essentially the client and the server in some way disconnect resulting in the server no longer being able to pass data (commands in my case) back to the client over the tunnel.

erebe commented 1 week ago

The issue come from the server receiving a new connection on the remote tunnel but no client picked it after 30seconds. At the moment, after those hard coded 30s elapsed, the server decide to close/shutdown the listening server, because if there is no client anymore, it means the listening server is not needed anymore.

It is a kind of gc to cleanup not needed remote tunnel.

Maybe this timeout of 30s is too short, and must be configurable.

Do you have by any chances the logs of the client at the same timestamp than the server message "Stopping listening server" to confirm this ?

debin-ge commented 1 week ago

The issue come from the server receiving a new connection on the remote tunnel but no client picked it after 30seconds. At the moment, after those hard coded 30s elapsed, the server decide to close/shutdown the listening server, because if there is no client anymore, it means the listening server is not needed anymore.

It is a kind of gc to cleanup not needed remote tunnel.

Maybe this timeout of 30s is too short, and must be configurable.

Do you have by any chances the logs of the client at the same timestamp than the server message "Stopping listening server" to confirm this ?

Sorry, I can't give logs of the client. When I found this problem, the command only gave the following information:

image
nxtreaming commented 1 week ago

The issue come from the server receiving a new connection on the remote tunnel but no client picked it after 30seconds. At the moment, after those hard coded 30s elapsed, the server decide to close/shutdown the listening server, because if there is no client anymore, it means the listening server is not needed anymore.

It is a kind of gc to cleanup not needed remote tunnel.

Maybe this timeout of 30s is too short, and must be configurable.

It should not perform gc in this scenario, Reverse tunnel works in the same way of a socks5 server, it SHOULD keep its live anytime ( always wait for a new connection).

erebe commented 1 week ago

You may want to try this pre-release https://github.com/erebe/wstunnel/releases/tag/v9.4.0 I have increased the gc timeout to 3min.

I will look at a later point how to improve reverse tunnels. In the meantime, if it can help you

debin-ge commented 1 week ago

You may want to try this pre-release https://github.com/erebe/wstunnel/releases/tag/v9.4.0 I have increased the gc timeout to 3min.您可能想尝试这个预发布 https://github.com/erebe/wstunnel/releases/tag/v9.4.0 我已将 gc 超时增加到 3 分钟。

I will look at a later point how to improve reverse tunnels. In the meantime, if it can help you稍后我将讨论如何改进反向隧道。同时,如果它可以帮助你

Thanks, this will be very helpful!

debin-ge commented 1 week ago

I used the latest release, but the problem is still not solved! Server: image

Clinet: image

erebe commented 1 week ago

@debin-ge I am not sure to understand how you end-up in this situation. The logs from the server and the client are hours apart, if your server close the reverse tunnel, it means the client is not connected anymore (and even after waiting for 3min). So even if the timeout disapear it will not make it works as the client is not there anyway to establish the reverse tunnel !

Can you explain me what the client is doing when the server close the reverse listening server ? Can you describe your expectations when no client is connected ?

debin-ge commented 1 week ago

The logs from the server and the client are hours apart, if your server close the reverse tunnel, it means the client is not connected anymore (and even after waiting for 3min). So even if the timeout disapear it will not make it works as the client is not there anyway to establish the reverse tunnel !

Can you explain me what the client is doing when the server close the reverse listening server ? Can you describe your expectations when no client is connected ?

This is because the client does not output any log messages either when the server connects or when the port is closed. I'd like the client and server to stay connected normally, or give an obvious error message when the reverse proxy closes

erebe commented 1 week ago

Can you start the client & server with wstunnel --log-lvl=debug client/server ... and share me all the logs without truncating them ? (You can send them to me be email)

debin-ge commented 1 week ago

I will restart the service and output the logs. I will send you the logs when an exception occurs. Thank you very much for your help.

erebe commented 1 week ago

(You may want to re-download the pre-release https://github.com/erebe/wstunnel/releases/tag/v9.4.0 , I have added tcp keelalive on the connection to help detect broken reverse tunel due to tcp stream being stale)

debin-ge commented 1 week ago

I've been observing it for a while and no new problems have arisen for the time being. I'm going to close this issue for now and I'll reopen it when new issues arise. Thanks to all for your help!