Skip to content

Commit

Permalink
🍴 darwin: obtain ForkLock when creating a socket
Browse files Browse the repository at this point in the history
  • Loading branch information
database64128 committed Sep 4, 2024
1 parent 1deca2c commit e79d3e3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions tfo_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"net"
"os"
"syscall"

"golang.org/x/sys/unix"
Expand Down Expand Up @@ -75,17 +76,22 @@ func (d *Dialer) socket(domain int) (fd int, err error) {
if d.MultipathTCP() {
domain = AF_MULTIPATH
}

syscall.ForkLock.RLock()
fd, err = unix.Socket(domain, unix.SOCK_STREAM, unix.IPPROTO_TCP)
if err != nil {
return
syscall.ForkLock.RUnlock()
return 0, os.NewSyscallError("socket", err)
}
unix.CloseOnExec(fd)
err = unix.SetNonblock(fd, true)
if err != nil {
syscall.ForkLock.RUnlock()

if err = unix.SetNonblock(fd, true); err != nil {
unix.Close(fd)
fd = 0
return 0, os.NewSyscallError("setnonblock", err)
}
return

return fd, nil
}

func (d *Dialer) setIPv6Only(fd int, family int, ipv6only bool) error {
Expand Down

0 comments on commit e79d3e3

Please sign in to comment.