On Fri, Mar 1, 2024 at 5:57 PM Jeff Stein <jeffst...@gmail.com> wrote:
>
> I'm struggling to understand if I'm able to do something.
>
>
> In my very odd use case we are writing a websever that handles connections 
> via a forked process.
>
> I have a listener process that listens for TCP connections.
>
> So each net.Conn that comes in we pull off its file descriptor:
>
> fd, err := conn.(*net.TCPConn).File()
>
> duplicate that file descriptor and then fork off a process passing in that 
> file descriptor.
>
> In my forked handler I'll reconstruct the HTTP connection and "do stuff".
>
> The concern I'm having is that it appears when I fork a process I inherit all 
> of the parent file descriptors so if I have say 5 incoming connections and 
> then I fork my child process technically could write to a different 
> connection.
>
> I've played around with the various options:
>
> cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: false,}
>
> and using cmd.ExtraFiles
>
> No matter what I do I seem unable to limit the sub process to ONLY using the 
> specific File Descriptor I want it to have access to.
>
> I believe this is doable in C - but I'm not sure if I can do this in GoLang 
> as-is without mods .

What you are describing shouldn't happen.  A child process should only
get the file descriptors explicitly passed via the os/exec.Cmd fields
Stdin, Stdout, Stderr, and ExtraFiles.  So tell us more: OS and
version of Go, and what is showing you that all file descriptors are
being passed down to the child.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUb27YBCyE52QisHLyB9XPPpEycMxt4FrFJogGsFMiemQ%40mail.gmail.com.

Reply via email to