-
Notifications
You must be signed in to change notification settings - Fork 297
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 callbacks to log when Ping/Pong is received #246
Comments
Hi! So this was intentional to avoid a callback based API. In order to measure latency, you just record the time when you call Ping and then when it returns and the difference is the ping pong. For logging you just log after it returns as well. I’ll be adding an example soon to make using Ping less confusing. See #227 |
Hello! Thanks for the quick answer! So basically the But then, how can I log the |
Yes, see 1695216#diff-7101a3ea121adf8d5b0acb5a2c520ca3R138-R162
You can't. Is there a reason you need to do that? |
Thanks!
Apart from logging, I've been trying to debug various scenarios in which I'm using web sockets, as well as stress testing, and it would be helpful to catch the information. I also have a scenario in which there's more information present in the |
That's a fair use case I didn't consider. Unfortunately I can't think of any good API to expose it. Using callbacks would be unfortunate and the stdlib http2 library also doesn't expose this sort of API either, instead favouring for a blocking Ping like us. For now, you can use gohack and add a log into the library itself in handleControl. |
Gohack sounds interesting, I'll look into that, thanks! |
Ok after considering it I think I'd be ok with adding two functions into the option structs that allow you to log when a ping/pong is received. I think for instrumentation and debugging purposes it's justified but the blocking |
I have a slightly different use case. I want the server to close dead client connections. If I know my clients are pinging every 'n' seconds, then if I don't see a ping in, say, 'n' * 2 then I can safely close the conn. Why do I want to do this? Because I have 1,000s or 100s of 1,000s of clients that are on flakey networks so I need to manage server resources by releasing dead sockets as quickly as possible. I know ping is designed to check for server responsiveness, but it can also be used to determine client liveness. That's my goal - to ask the question, is the client still alive. So any mechanism that lets the server know it is getting a ping works for me. I don't care much what it is, but some way of knowing that the client has pinged (and thus whether a client hasn't pinged) is valuable. |
…ame in. This should address coder#246.
Hello,
From what I've seen, the
pong
is automatically handled internally in the library, however, in some specific cases it could be useful to run a function when thepong
comes back (i.e. measuring latency, logging, etc.)Think it would be ok to add a handler function that is called when the
pong
is handled, which can be set through an exposed function ?The text was updated successfully, but these errors were encountered: