yudai / gotty

Share your terminal as a web application
MIT License
18.79k stars 1.38k forks source link

It's better to add "timeout" option #78

Closed tczf1128 closed 7 years ago

tczf1128 commented 9 years ago

gotty exit if no client connect to it

yudai commented 9 years ago

Hi, could you describe your use case that needs timeout?

tczf1128 commented 9 years ago

I use gotty with docker exec -it DOCKER_ID /bin/bash to show the terminal of container, then users can access to the container, and if no one connect it in 10 minutes, the gotty should exit

yudai commented 9 years ago

Thanks.

I feel like it's a bit special use case, so let me keep this issue open to collect the same request from others.

tczf1128 commented 9 years ago

Thanks

wagnersza commented 8 years ago

+1 the same case

zyfdegh commented 8 years ago

+1 almost the same case. I need timeout option too. Quit command is also OK. I hacked gotty and use it parallel to call command. In this way, it supports mutilple connections.

zyfdegh commented 8 years ago

I figured out a solution, but it's not perfect so far. I set a count down timer when each connection is established. It will do the following.

  1. The timeout interval is set when you run gotty like gotty -w --timeout=60 <cmd>.
  2. The left time is decreasing 1 every second since the connection is established. If user has no operation on the gotty web page, it will count down to 0 and will trigger a function named boom which will cause disconnection.
  3. The left time will be set to init value if the user has typed anything on gotty web page. To say technically, function Rewind() will be called inside processReceive() and processSend(). The Rewind() function will set the left time to initial value(the one in gotty command line). The timer will count down again and do same thing in step 2. It works like a old-fashioned stopwatch.

The issue is, when I run command like sleep 80 or start a long-run programme like top. It will disconnect when timeout. This bothers in some cases.

zyfdegh commented 8 years ago

PR is in #115 . It differ a bit as @tczf1128 descripbed the issue. Gotty will not exit when timeout, but the cmd will exit and gotty web page shows a Connection closed label.

oneumyvakin commented 8 years ago

+1 I need timeout to free TCP port for further connections. My case is multiple GoTTY instances running on one server in a specific port range, I'd like to use timeout to free used ports and server resources.

oneumyvakin commented 8 years ago

@zyfdegh Thanks for your work and the PR. It's possible to make optionally GoTTY exit/no exit behaviour? Maybe one more command line option?

zyfdegh commented 8 years ago

@oneumyvakin View my fork on github.com/zyfdegh/gotty, it supports --timeout option. But I modified some source codes, so gotty will work a bit differently.

yudai commented 7 years ago

Added --timeout option :)