-
Notifications
You must be signed in to change notification settings - Fork 138
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
Add API to get current number of WebSocket connections #43
base: master
Are you sure you want to change the base?
Conversation
How about a signal handler instead? Something like |
It's ok for signal handler, but how to know whether there are no current users or not. So required a method to know current user number(e.g.: connection number in this PR). If request API to fetch result |
I honestly don't feel comfortable exposing this information to every user. With the signal handler, you wouldn't need to know ahead of time whether there are active connections. You could just send the signal. If no one is logged in, it could terminate GoTTY. If there are active connections, it could log how many. |
👍 I have understood your meanings in preview comment now... I'll look this hidden and advanced feature according your tips. Thanks your advice for this! |
Signed-off-by: Chenyang Yan <[email protected]>
a69c369
to
04f6d63
Compare
Rebased and updated with signal handler. It's ready to review it again. @sorenisanerd |
There's already some signal handling in Sending yourself a signal while handling another signal technically works, but I'd prefer if you didn't. Perhaps you can get away with "falling through" in the switch statement in the signal handler if the number of connections is >0. |
I see. Because
|
I see what you're saying. Can we take a step back? Why can't you use the graceful shutdown option? I wonder if there's a better way to do this. |
Another a question, with signal handler to kill process or logging(not response JSON), it will produce extra burden for caller if running in K8S Readiness Probe or Livness Probe:
Could you provide more details about |
When you send gotty a SIGINT (Ctrl-C, for instance), it stops accepting new
connections and terminates once all sessions have ended.
|
After investigating, no any better method is suitable for my usecase situation
|
How to send? `kill -2 $(pidof gotty)` will do the trick. That's the same as
hitting Ctrl-C on the controlling tty.
When to send it? I have no idea. I still don't understand the use case.
When would you use the API you're proposing?
|
Yes, send signal to process, I have got that point.
I will request API periodically with goroutine and will request N times. If If someone want use it again, will create a new process; similarly, if no anyone use it( |
Why not just send |
If send 2 signal directly, new connection will be confused(connected will wait to be closed). When to send this signal(how do it know no one is using it for code, so required a method to know) Here is cull inactive terminal with pseudocode based on connection number:
|
Can we just add another signal handler that, if there are connected clients it does nothing, but if there are no connected clients, it terminates gotty? Would that do the trick? I really don't want to expose stuff like number of clients to all users. If we had separate user vs admin concepts or something, it'd be a different story. |
Thanks your patient for this issue!
About another signal handler, it will produce another problem based on k8s app. Since
About signal handler, maybe
I prefer to JSON method in generally. After rethinking, if you really don't want to expose stuff like number of clients to all users, I will add signal handler for PR and rebase update it. |
You could also just look at open sockets in |
I want to kill gotty main process to release resources if not one use it, so required a method to get current WebSocket connections number
About use it definition:
Signed-off-by: Chenyang Yan [email protected]