Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wstunnel stdio does not exit / stuck in a loop #93

Closed
streaps opened this issue Sep 25, 2021 · 8 comments
Closed

wstunnel stdio does not exit / stuck in a loop #93

streaps opened this issue Sep 25, 2021 · 8 comments
Labels

Comments

@streaps
Copy link

streaps commented Sep 25, 2021

I have a problem to get wstunnel -L stdio work with some software. It looks like wstunnel doesn't exit and tries to connect again and again. Simple example

$ echo "Hello Server" | wstunnel -L stdio:localhost:1234 wss://example.com
Hello Client!
CLOSE tunnel :: 127.0.0.1:0 <==WSS==> example.com:443 <==STDIO==> localhost:1234
CLOSE tunnel :: 127.0.0.1:0 <==WSS==> example.com:443 <==STDIO==> localhost:1234
CLOSE tunnel :: 127.0.0.1:0 <==WSS==> example.com:443 <==STDIO==> localhost:1234
[...]

This does work though:

$ echo "Hello Server" | ncat --proxy 127.0.0.1:1080 --proxy-type socks5 localhost 1234
Hello Client!
$

(port 1080 is wstunnel)

There are also no issues with ssh and ProxyCommand wstunnel -L stdio:...

@erebe
Copy link
Owner

erebe commented Oct 11, 2021

Hello,

Thanks for reporting !
Have to check if it is a feature or a bug, basically if the tunnel get disconnect we keep retrying to establish a new one.
I am not sure if this behavior is desirable when there is a connection issue (as it will automatically reconnect you)
In your case it is clearly a pain, as you can't exist the program without killing wstunnel

🤔

@erebe erebe added the bug label Apr 16, 2022
@struanb
Copy link

struanb commented Sep 3, 2023

Any update on this issue? When using wstunnel with ssh, we want wstunnel to exit if the server closes the connection, but currently we get the infinite loop of error messages described above.

Is what we need a command-line option that tells wstunnel to exit immediately in the case its initial connection, once made, is clsed?

@erebe
Copy link
Owner

erebe commented Sep 9, 2023

Will try to get a look at it this week, and coming back to you

@erebe
Copy link
Owner

erebe commented Sep 14, 2023

Hey,
I gave it a shot, would you mind trying this release and let know if it matches your expectations
https://github.com/erebe/wstunnel/suites/16183624020/artifacts/924199162 (linux)
https://github.com/erebe/wstunnel/suites/16183624020/artifacts/924199164 (mac)
https://github.com/erebe/wstunnel/suites/16183624020/artifacts/924199165 (windows)

@struanb
Copy link

struanb commented Sep 17, 2023

Thanks for doing this. I've tested the mac version, in conjunction with ssh. It works well.

Here are before and after logs from an ssh connection made via wstunnel, when the remote wstunnel dies.

Before:

CLOSE tunnel :: 127.0.0.1:0 <==WSS==> myserver:443 <==STDIO==> 127.0.0.1:22
[hangs]
ERROR :: Cannot establish websocket connection with the server
                               ERROR :: Cannot establish websocket connection with the server
                                                                                             ERROR :: Cannot establish websocket connection with the server
                                                                                                                                                           ERROR :: Cannot establish websocket connection with the server
                                                         ERROR :: Cannot establish websocket connection with the server
                                                                                                                       ERROR :: Cannot establish websocket connection with the server
                     ERROR :: Cannot establish websocket connection with the server
                                                                                   ERROR :: Cannot establish websocket connection with the server
                                                                                                                                                 ERROR :: Cannot establish websocket connection with the server
[loops indefinitely]

After:

CLOSE tunnel :: 127.0.0.1:0 <==WSS==> myserver:443 <==STDIO==> 127.0.0.1:22
                                                                                                                                 CLOSE stdio server
                                                                                                                                                   Bad packet length 3702688319.
ssh_dispatch_run_fatal: Connection to UNKNOWN port 65535: Connection corrupted

Will the new version need a command line option that enables the new behaviour, or do you feel the new behaviour is better in all cases?

@erebe
Copy link
Owner

erebe commented Sep 19, 2023

I think I will not add a flag, and make this behavior the default.
If stdin close, there is not much we can do to resume the connection. The only way is to spawn a new process to get a fresh stdin.
if it is the remote connection that close, well, it is super hard to resume it because there is no way anymore to know what data has been sent or if some has been lost in the middle, so the only way is to restart a new connection, and sadly with stdin there is no feedback loop possible to notify the program to tell it re-open a new cnx.

So I will make it the default and see if some users complains

@struanb
Copy link

struanb commented Sep 20, 2023

Makes complete sense.

@erebe
Copy link
Owner

erebe commented Sep 24, 2023

@erebe erebe closed this as completed Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants