-
Notifications
You must be signed in to change notification settings - Fork 143
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
Way to share all parent connections #2
Comments
If you mean listeners, there might be a possibility to support this. Can you describe your use case some more? Not sure I understand you correctly. |
I have a program that create some tcp listeners that accepts connections ( |
I wrote a small snippet, most likely it does not work, but I hope that this will help to understand |
Ok, I think I know what you want now. Unfortunately, AddConn and Conn don't work the way you'd like them to. The idea is to use them for https://golang.org/pkg/net/#UnixConn and similar. Making this work for stream based connections is actually quite tricky, because the parent and the child have to coordinate. Example: you have a HTTP connection, first the parent reads from it, then the child, then the parent again. Now both processes have pieces of the data, and its impossible to continue using the connection in either process. What would you do with this if it worked? I imagine you want to avoid closing client connections outright? |
Yes, I wrapped tcp connection in bufio.Reader to reduce the number of system calls and read packages with fixed length over tcp connection. Then I wrote the logic that allows handle all data from buffer before upgrade, therefore, the child process can start reading a new package from the connection without problems. There are several methods for transferring active sockets (connections), one of which is to pack the connection and its state, and send it to a new process. But I choose a simpler way. Thank you for answers, Lorenz. |
It's so strange, but I got what I wanted! Now when I accept new connection in parent process I call It looks like it works well. At the same time, I understand that these functions helpers are "crutches". What do you think, is it possible to implement something like that in this library? |
Ha, that's a a very cool hack! Have you tried hammering this a bit, to make sure that this works? I'm worried that there is a race condition in the old process:
There is a good chance you will not pass the connection to the new process. It's possible to make this safe, but it would require changing the API quite a bit which I'd rather not do. |
Yes, I made simple program on Python that send many packages over tcp to my server. Maybe you could tell me how to do it better, I would love to do a fork if you don't want to change the architecture of the library. |
Ok, I've thought about this, and I don't think it's easily doable. It
boils down to this:
```
conn := ln.Accept()
// race
fds.AddConn(conn)
```
To prevent this, you could add a mutex:
```
mutex.Lock()
conn := ln.Accept()
// no race!
fds.AddConn(conn)
mutex.Unlock()
```
This fails because Accept() blocks, which means you won't be able to
upgrade your process (unless a new connection comes in). I can't see a
simple way to circumvent this, sorry.
Is it OK if I close this issue?
…On Tue, 16 Oct 2018 at 19:14, bm0 ***@***.***> wrote:
Yes, I made simple program on Python that send many packages over tcp to my server.
I would like to pass all connections as much as possible, but I don't have such a task, instead I try to pass everything that is possible to the child process.
Of course, it would be very nice to have such an opportunity, but I'm not yet familiar enough with the library's code to implement it.
Maybe you could tell me how to do it better, I would love to do a fork if you don't want to change the architecture of the library.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
--
Lorenz Bauer | Systems Engineer
25 Lavington St., London SE1 0NZ
www.cloudflare.com
|
Closing this, sorry I don't have a better answer. |
Ok, thank you! |
Hello everyone!
Is there a way to share all the active connections between processes?
I see only one way, use
Fds.Conn()
method, but i must knowaddr
in parent process for this.It may be worth adding methods that will return all parent connections and listeners?
It would be amazing.
The text was updated successfully, but these errors were encountered: