{"record":{"id":"fd76e1d211ce503f","repo":"gravitational/teleport","slug":"xpc-connection-invalid","errorCode":null,"errorMessage":"XPC connection invalid","messagePattern":"XPC connection invalid","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vnet/daemon/common_darwin.go","lineNumber":64,"sourceCode":"\terrorCodeMissingCodeSigningIdentifiers = int(C.VNEMissingCodeSigningIdentifiersError)\n\terrMissingCodeSigningIdentifiers       = errors.New(\"either identifier or team identifier is missing in code signing information; is the binary signed?\")\n)\n\nvar (\n\t// nsCocoaErrorDomain is a generic error domain used in a lot of Apple's Cocoa frameworks.\n\tnsCocoaErrorDomain = \"NSCocoaErrorDomain\"\n\n\t// https://developer.apple.com/documentation/foundation/nsxpcconnectioninterrupted-swift.var\n\terrorCodeNSXPCConnectionInterrupted = int(C.NSXPCConnectionInterrupted)\n\terrXPCConnectionInterrupted         = errors.New(\"XPC connection interrupted\")\n\n\t// https://developer.apple.com/documentation/foundation/nsxpcconnectioncodesigningrequirementfailure-swift.var\n\terrorCodeNSXPCConnectionCodeSigningRequirementFailure = int(C.NSXPCConnectionCodeSigningRequirementFailure)\n\terrXPCConnectionCodeSigningRequirementFailure         = errors.New(\"code signing requirement failed\")\n\n\t// https://developer.apple.com/documentation/foundation/nsxpcconnectioninvalid-swift.var\n\terrorCodeNSXPCConnectionInvalid = int(C.NSXPCConnectionInvalid)\n\terrXPCConnectionInvalid         = errors.New(\"XPC connection invalid\")\n)\n\nfunc DaemonLabel() (string, error) {\n\tpath, err := darwinbundle.Path()\n\tif err != nil {\n\t\treturn \"\", trace.Wrap(err)\n\t}\n\n\tcPath := C.CString(path)\n\tdefer C.free(unsafe.Pointer(cPath))\n\n\tcLabel := C.DaemonLabel(cPath)\n\tdefer C.free(unsafe.Pointer(cLabel))\n\n\tlabel := C.GoString(cLabel)\n\n\tif label == \"\" {\n\t\treturn \"\", trace.Errorf(\"could not get details for bundle under %s\", path)","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/gravitational/teleport/blob/1283425b60ec5f60d509ba4c791183d452923ff7/lib/vnet/daemon/common_darwin.go#L46-L82","documentation":"errXPCConnectionInvalid (lib/vnet/daemon/common_darwin.go:64) maps NSXPCConnectionInvalid from NSCocoaErrorDomain, typically 'No such process' — the XPC service endpoint does not (yet) exist. On first launch after the user enables the login item, SMAppService can report 'enabled' before launchd has finished submitting the job, so the very first connection attempt can fail with this error.","triggerScenarios":"RegisterAndCall -> startByCalling when the daemon XPC service is not registered/running yet: right after enabling the login item, if the daemon job was never launched, or after the daemon was unloaded/booted out. RegisterAndCall retries up to 3 times with 500ms delays when enablement was just performed.","commonSituations":"First run after approving the login item in System Settings (launchd race); daemon label never registered; launchd job disabled; bundle path changed so the old service is not found.","solutions":["Retry after a short delay — the built-in retry (3 attempts, 500ms apart) usually resolves the launchd registration race.","Verify the daemon is registered: check SMAppService status / `launchctl print system/<label>` and re-register if not registered.","Confirm the app bundle path is correct and the daemon is enabled in Login Items; re-register with RegisterDaemon if needed."],"exampleFix":"// before: single attempt\nerr := startByCalling(ctx, bundlePath, cfg)\n// after: tolerate the launchd race like RegisterAndCall does\nfor retries := 0; errors.Is(err, errXPCConnectionInvalid) && retries < 3; retries++ {\n    time.Sleep(500 * time.Millisecond)\n    err = startByCalling(ctx, bundlePath, cfg)\n}","handlingStrategy":"retry","validationCode":"// confirm the daemon job is registered before connecting\nstatus, err := daemonStatus(bundlePath)\nif err != nil || status != vnetdaemon.ServiceStatusEnabled {\n    return errors.New(\"daemon not registered/enabled yet; register first\")\n}","typeGuard":"func isXPCConnectionInvalid(err error) bool { return errors.Is(err, vnetdaemon.ErrXPCConnectionInvalid) }","tryCatchPattern":"err := startByCalling(ctx, bundlePath, cfg)\nfor retries := 0; errors.Is(err, vnetdaemon.ErrXPCConnectionInvalid) && retries < 3; retries++ {\n    time.Sleep(500 * time.Millisecond)\n    err = startByCalling(ctx, bundlePath, cfg)\n}","preventionTips":["After enabling the login item, expect a launchd registration race; always retry the first connection.","Verify registration status via SMAppService before starting.","Keep the app bundle path stable; moving it invalidates the registered service."],"tags":["macos","xpc","launchd","vnet"],"backgroundTag":"xpc-connection-invalid","analyzedSha":"1283425b60ec5f60d509ba4c791183d452923ff7","analyzedAt":"2026-09-02T04:06:41.601Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}