Re: [go-nuts] Limiting File Descriptors on Forked Linux cmd.exec

2024-03-04 Thread Jeff Stein
And looking through the source code on os.exec_linux I think I've also validated this as well: if fd[i] == i { // dup2(i, i) won't clear close-on-exec flag on Linux, // probably not elsewhere either. _, _, err1 = RawSyscall(fcntl64Syscall, uintptr(fd[i]), F_SETFD, 0) if err1 != 0 { goto

Re: [go-nuts] Limiting File Descriptors on Forked Linux cmd.exec

2024-03-04 Thread Jeff Stein
It appears this was in fact the issue. I added some code to print out the `FD_CLOEXEC` state. Files called via *syscall.Dupe2* end up with a *FD_CLOEXEC=0* whereas anything passed via *ExtraFiles* has a *FDCLOEXEC=1.* Whoever said "This is impossible" thanks - you spurred me towards a

Re: [go-nuts] Limiting File Descriptors on Forked Linux cmd.exec

2024-03-04 Thread Jeff Stein
I think I may have discovered the issue. I made a sys call to duplicate the file descriptor dupFd, err := syscall.Dup(int(file.Fd())) if err != nil { log.Printf("Error duplicating file descriptor: %v", err) return 0, "" } which likely reset the FD_CLOEXEC Flag: (from Advanced Programming in

Re: [go-nuts] Limiting File Descriptors on Forked Linux cmd.exec

2024-03-04 Thread Jeff Stein
OP here -> I'm going to put together some test apps - toss them on GitHub and make sure I actually know what I'm talking about :) On Friday, March 1, 2024 at 7:57:15 PM UTC-7 Ian Lance Taylor wrote: > On Fri, Mar 1, 2024 at 6:17 PM Robert Engels wrote: > > > > The could be calling fork() as

Re: [go-nuts] Limiting File Descriptors on Forked Linux cmd.exec

2024-03-01 Thread Ian Lance Taylor
On Fri, Mar 1, 2024 at 6:17 PM Robert Engels wrote: > > The could be calling fork() as in the system call - which copies all file > descriptors but I didn’t think Go processes could fork. > > Seems you would need to remap stdin and stdout in the fork to do anything > useful. > > This sounds

Re: [go-nuts] Limiting File Descriptors on Forked Linux cmd.exec

2024-03-01 Thread Robert Engels
The could be calling fork() as in the system call - which copies all file descriptors but I didn’t think Go processes could fork. Seems you would need to remap stdin and stdout in the fork to do anything useful. This sounds very PHP - what goes around comes around. > On Mar 1, 2024, at 8:01 

Re: [go-nuts] Limiting File Descriptors on Forked Linux cmd.exec

2024-03-01 Thread Ian Lance Taylor
On Fri, Mar 1, 2024 at 5:57 PM Jeff Stein 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

[go-nuts] Limiting File Descriptors on Forked Linux cmd.exec

2024-03-01 Thread Jeff Stein
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 :=