{"record":{"id":"69dfec30c124b50f","repo":"slackhq/nebula","slug":"setnonblock-v","errorCode":null,"errorMessage":"SetNonblock: %v","messagePattern":"SetNonblock: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"overlay/tun_darwin.go","lineNumber":120,"sourceCode":"\t\treturn nil, fmt.Errorf(\"CTLIOCGINFO: %v\", err)\n\t}\n\n\terr = unix.Connect(fd, &unix.SockaddrCtl{\n\t\tID:   ctlInfo.Id,\n\t\tUnit: uint32(ifIndex) + 1,\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"SYS_CONNECT: %v\", err)\n\t}\n\n\tname, err = unix.GetsockoptString(fd, unix.AF_SYS_CONTROL, _UTUN_OPT_IFNAME)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to retrieve tun name: %w\", err)\n\t}\n\n\terr = unix.SetNonblock(fd, true)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"SetNonblock: %v\", err)\n\t}\n\n\tt := &tun{\n\t\tf:           os.NewFile(uintptr(fd), \"\"),\n\t\tDevice:      name,\n\t\tvpnNetworks: vpnNetworks,\n\t\tDefaultMTU:  c.GetInt(\"tun.mtu\", DefaultMTU),\n\t\tl:           l,\n\t}\n\n\terr = t.reload(c, true)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tc.RegisterReloadCallback(func(c *config.C) {\n\t\terr := t.reload(c, false)\n\t\tif err != nil {","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/slackhq/nebula/blob/dd8f660c0ac37903ec4080ca4d3c861ba9342ceb/overlay/tun_darwin.go#L102-L138","documentation":"Once the utun is connected and named, newTun puts the file descriptor into non-blocking mode with unix.SetNonblock so nebula can integrate it with its read loops. If SetNonblock fails, this error wraps the errno. Failure here means the fd exists but its flags cannot be manipulated, which is very unusual.","triggerScenarios":"unix.SetNonblock(fd, true) returns an error — invalid fd state, fd closed concurrently by another goroutine, or resource exhaustion (EBADF/ENOMEM class errors).","commonSituations":"Concurrent shutdown racing startup (Close called while Activate/newTun runs); extreme fd exhaustion from leaked descriptors; kernel bugs on unusual macOS versions.","solutions":["Check for duplicate nebula instances racing over the same TUN lifecycle and ensure only one manages the device.","Inspect open file descriptor limits (ulimit -n) and close leaks; retry after freeing descriptors.","Restart the host if the fd table is corrupted (EBADF on a freshly created fd is otherwise nearly impossible)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := start(); err != nil && strings.Contains(err.Error(), \"SetNonblock\") {\n    // check fd limits and for concurrent Close() racing startup\n}","preventionTips":["Ensure only one goroutine owns the TUN lifecycle (no Close during startup)","Raise fd limits (ulimit -n) if running many tunnels in one process","Audit for descriptor leaks when running long-lived processes"],"tags":["macos","darwin","utun","file-descriptor","nonblocking"],"backgroundTag":"fcntl-nonblock-failed","analyzedSha":"dd8f660c0ac37903ec4080ca4d3c861ba9342ceb","analyzedAt":"2026-09-03T11:13:55.444Z","contentChangedAt":"2026-09-03T11:13:55.444Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}