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

Draft: Use TCP KEEPALIVE to force closing socket with offline remotes. #4761

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stephan57160
Copy link
Contributor

Close issue #4729.

@stephan57160
Copy link
Contributor Author

OK. Let's talk about this lazy implementation.

On Linux, after ::accept(), TCP_KEEPALIVE is not set by default.
Moreover, there is no way for an application to retreive this socket
and then, no way to close() or use setsockopt() on it.
So, the only possibility to avoid socket leakage is TCP_KEEPALIVE.

Regarding the values, the default TCP ones are far too huge (> 2h).
The values below seem reasonnable for a ZYRE application :

120 + 10 * 10 = 220s (3mn 40s)

Note:

A ZYRE client application will reset its side after about 30s, so
no worry about such applications.
What about other applications ?

@stephan57160 stephan57160 changed the title DRAFT - Use TCP KEEPALIVE to force closing socket with offline remotes. Draft: Use TCP KEEPALIVE to force closing socket with offline remotes. Dec 20, 2024
@bluca
Copy link
Member

bluca commented Dec 20, 2024

There are options for this, pretty sure zyre should just set them accordingly, rather than hardcoding?

@stephan57160
Copy link
Contributor Author

Agreed, and I spent quite some time trying to find something less hard-coded,but I did not find anything.

For instance, when the socket is created internally by a ZYRE node, the application has no possibility to access it.
A least, I did not find any way to do that.

If you have a pointer, I'll see what I can do with it.

@bluca
Copy link
Member

bluca commented Dec 20, 2024

ZMQ_TCP_KEEPALIVE
ZMQ_TCP_KEEPALIVE_CNT
ZMQ_TCP_KEEPALIVE_IDLE
ZMQ_TCP_KEEPALIVE_INTVL

@stephan57160
Copy link
Contributor Author

Not sure to understand what you have in mind.

I you use zmq_set_sockopt(sock, ZMQ_TCP_XXX, ...), you have to handle a bunch of if error cases.
All are handled by tune_tcp_keepalives().

What I can do is to use constants for 10, 10 and 120, right, but I still have to tune TCP KA right after the call to accept(),
as not possible from the application.

@bluca
Copy link
Member

bluca commented Dec 20, 2024

I mean that zyre or any other application should just use those options if they want to modify this behaviour

@stephan57160
Copy link
Contributor Author

Agreed.
Unfortunatelly, ZYRE applications have a limited access to the socket layer.

It's being a long time I worked on this but I'm pretty sure that even the ZACTOR has no view on the accept()'ing socket.

@bluca
Copy link
Member

bluca commented Dec 20, 2024

I am pretty sure you can get the zmq socket in all of those cases, and then it's just a matter of setting those options

@stephan57160
Copy link
Contributor Author

If this way exists, I lost on this Hide & Seek :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants