Comments (12)
Is there a way to share all the active connections between processes?
If you mean client connections (think established TCP sockets) then no. Migrating these between processes usually involves migrating application state as well, which is complicated and error prone.
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.
from tableflip.
I have a program that create some tcp listeners that accepts connections (net.Conn
).
Now i can use parent listeners in child process, but how i can use connections that accepted in parent process?
from tableflip.
I wrote a small snippet, most likely it does not work, but I hope that this will help to understand
https://gist.github.com/bm0/e645392b7274964bf23dcf4ee7fd56a5
from tableflip.
In other words, can you give an example of how to properly use a AddConn and Conn functions?
from tableflip.
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?
from tableflip.
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.
from tableflip.
It's so strange, but I got what I wanted!
I wrote two helper functions to add and get connections.
https://gist.github.com/bm0/fbd8285e3319af9efe83c3193ac17acf
Now when I accept new connection in parent process I call appendConnAddr
After update I call getInheritConns
in child process and handle inherited connections.
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?
from tableflip.
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:
- call ln.Accept()
- other go routine: call upg.Upgrade()
- call upg.Fds.AddConn() <- this does not add conn from 1 to upgrade from 2
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.
from tableflip.
Yes, I made simple program on Python that send many packages over tcp to my server.
I would like to pass all connections, 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.
from tableflip.
from tableflip.
Closing this, sorry I don't have a better answer.
from tableflip.
Ok, thank you!
from tableflip.
Related Issues (20)
- supervisord HOT 4
- [Question] Windows HOT 4
- Expose parent presence
- sometimes got error like "listen tcp xxx: bind: address already in use" when Upgrade HOT 4
- support unix socket HOT 2
- Logs go missing after systemd-journald restart HOT 2
- How to integrate with systemd and supervisor? HOT 2
- Impossible to build for windows HOT 2
- Add an example for supervisord integration HOT 1
- Enable SO_REUSEPORT HOT 1
- Allow multiple back-to-back graceful upgrades HOT 1
- Request for updating README.MD HOT 1
- Keep foreground control with signal propagation after successful upgrade HOT 5
- Hello, is https not supported? HOT 1
- upg.Exit() do not effective in go routine ? HOT 1
- [Bug] Connections not closed on inherited net.Conn HOT 2
- Can't catch syscall.SIGINT after upgrade HOT 1
- how can i use it for rpcx restart
- Overseer HOT 3
- Upgrade function documentation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tableflip.