{"record":{"id":"b311422fb648e0a9","repo":"larksuite/cli","slug":"bus-listen-w","errorCode":null,"errorMessage":"bus listen: %w","messagePattern":"bus listen: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/event/bus/bus.go","lineNumber":108,"sourceCode":"\t\t\tb.logger.Printf(\"Another bus already holds %s/bus.alive.lock, exiting\", eventsDir)\n\t\t\treturn nil\n\t\t}\n\t\tb.logger.Printf(\"[bus] pid file write failed: %v (status discovery may miss this bus)\", pidErr)\n\t} else {\n\t\tb.pidHandle = pidHandle\n\t}\n\n\tln, err := b.transport.Listen(addr)\n\tif err != nil {\n\t\tif probe, dialErr := b.transport.Dial(addr); dialErr == nil {\n\t\t\tprobe.Close()\n\t\t\tb.logger.Printf(\"Another bus is already running for %s, exiting\", b.appID)\n\t\t\treturn nil\n\t\t}\n\t\tb.transport.Cleanup(addr)\n\t\tln, err = b.transport.Listen(addr)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"bus listen: %w\", err)\n\t\t}\n\t}\n\tb.listener = ln\n\tb.logger.Printf(\"Bus started for app=%s pid=%d addr=%s\", b.appID, os.Getpid(), addr)\n\n\tb.idleTimer = time.NewTimer(idleTimeout)\n\n\tsourceCtx, sourceCancel := context.WithCancel(ctx)\n\tdefer sourceCancel()\n\tb.startSources(sourceCtx)\n\n\tacceptDone := make(chan struct{})\n\tgo func() {\n\t\tdefer close(acceptDone)\n\t\tb.acceptLoop(ctx)\n\t}()\n\n\t// Re-check live conn count under lock: a stale idle tick can linger past a concurrent Stop+Reset.","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/event/bus/bus.go#L90-L126","documentation":"Bus.Run in internal/event/bus/bus.go fails when the transport cannot bind the listen address for this app's event bus. After cleanup of a stale socket it retries transport.Listen once; if binding still fails the error is wrapped as \"bus listen: %w\" and returned, aborting bus startup. The cause is the underlying transport (e.g. Unix socket) error.","triggerScenarios":"Run() reaches transport.Listen(addr) and it returns an error: address already in use by a live foreign process, permission denied on the socket path/socket directory, socket directory missing, or path too long. This happens only when this process is not reusing an existing healthy bus (otherwise it exits early with nil).","commonSituations":"Another lark-cli process still holds the socket so Cleanup could not remove it; stale socket owned by a different user; LARKSUITE_CLI_CONFIG_DIR on a read-only or nonexistent path; container with a full or restricted tmp dir.","solutions":["Check the wrapped cause: 'address already in use' means a live process owns the socket — stop it or wait for it to exit","Remove the stale socket file at addr manually if no bus process is running (rm the socket path under the config dir)","Ensure the socket's parent directory exists, is writable, and is owned by the current user","Verify LARKSUITE_CLI_CONFIG_DIR points to a writable location; rerun the command"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if fi, err := os.Stat(socketDir); err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"bus socket dir %s unavailable\", socketDir)\n}","typeGuard":"func isListenError(err error) bool { return err != nil && strings.Contains(err.Error(), \"bus listen:\") }","tryCatchPattern":"if err := bus.Run(ctx); err != nil {\n    var wrapped interface{ Unwrap() error }\n    if errors.As(err, &inner) && isAddrInUse(inner) {\n        // stop stale process or remove stale socket, then retry once\n    }\n    return err\n}","preventionTips":["Ensure the bus socket directory exists and is writable by the current user","Stop orphaned lark-cli processes that hold the socket before restarting","Keep LARKSUITE_CLI_CONFIG_DIR on a stable writable path","Rely on the library's Cleanup/retry-once path instead of removing sockets concurrently"],"tags":["network","unix-socket","bus","listen"],"backgroundTag":"address-already-in-use","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}