larksuite/cli · warning
busdiscover: malformed pid file %s
Error message
busdiscover: malformed pid file %s
What it means
readPIDFile throws this when the bus.pid file exists but does not contain the expected two-line payload (PID line + RFC3339 timestamp line). The scanner (scanLiveBuses via isBusAlive) treats the bus as live but logs this diagnostic and reports the process with PID 0, so it is a data-integrity signal rather than a fatal failure.
Source
Thrown at internal/event/adapter/localbus/busdiscover/pidfile.go:70
return nil, fmt.Errorf("busdiscover: write pid tmp: %w", err)
}
if err := vfs.Rename(tmpPath, pidPath); err != nil {
_ = vfs.Remove(tmpPath)
_ = lock.Unlock()
return nil, fmt.Errorf("busdiscover: rename pid file: %w", err)
}
return &Handle{lock: lock}, nil
}
func readPIDFile(eventsDir string) (int, time.Time, error) {
pidPath := filepath.Join(eventsDir, pidFileName)
data, err := vfs.ReadFile(pidPath)
if err != nil {
return 0, time.Time{}, err
}
lines := strings.SplitN(strings.TrimSpace(string(data)), "\n", 2)
if len(lines) < 2 {
return 0, time.Time{}, fmt.Errorf("busdiscover: malformed pid file %s", pidPath)
}
pid, err := strconv.Atoi(strings.TrimSpace(lines[0]))
if err != nil {
return 0, time.Time{}, fmt.Errorf("busdiscover: malformed pid in %s: %w", pidPath, err)
}
startTime, err := time.Parse(time.RFC3339, strings.TrimSpace(lines[1]))
if err != nil {
return 0, time.Time{}, fmt.Errorf("busdiscover: malformed timestamp in %s: %w", pidPath, err)
}
return pid, startTime, nil
}
// isBusAlive: try-lock the alive file. ErrHeld = live holder; success = stale (release immediately).
func isBusAlive(appDir string) bool {
lockPath := filepath.Join(appDir, aliveLockFileName)
if _, err := vfs.Stat(lockPath); err != nil {
return false
}View on GitHub (pinned to 7fd6ef3c07)
Solutions
- Delete the corrupt bus.pid and restart the bus process so WritePIDFile republishes a valid file (the alive lock still proves liveness)
- Check file content with cat bus.pid — expect '<pid>\n<RFC3339 timestamp>' and fix if manually edited
- If the owning bus process is dead, remove the whole stale app dir; the try-lock probe will then report it not alive
- If this recurs, check for disk corruption or tools that rewrite files non-atomically in the state dir
Example fix
// before: truncated pid file -> live bus reported with PID 0 $ cat ~/.larkcli/events/<appID>/bus.pid 1234 // after: delete and let the bus republish $ rm ~/.larkcli/events/<appID>/bus.pid && restart the bus process $ cat ~/.larkcli/events/<appID>/bus.pid 1234 2026-09-04T08:00:00Z
Defensive patterns
Strategy: fallback
Type guard
// Treat PID 0 as 'liveness known, pid unknown' when consuming scan results
func hasUsablePID(p busdiscover.Process) bool { return p.PID > 0 }
// Validate a pid file's shape before relying on it
func pidFileLooksValid(path string) bool {
data, err := os.ReadFile(path)
if err != nil { return false }
lines := strings.SplitN(strings.TrimSpace(string(data)), "\n", 2)
if len(lines) < 2 { return false }
if _, err := strconv.Atoi(strings.TrimSpace(lines[0])); err != nil { return false }
_, err = time.Parse(time.RFC3339, strings.TrimSpace(lines[1]))
return err == nil
} Try / catch
procs, err := scanLiveBuses(eventsDir) // readPIDFile failure is logged, not returned
for _, p := range procs {
if p.PID == 0 {
// live lock held but pid file unreadable: cannot signal; treat as unmanaged live bus
continue
}
// safe to signal p.PID
} Prevention
- Do not hand-edit bus.pid; let WritePIDFile publish it atomically
- Kill -9 of the bus can leave truncated files — prefer graceful shutdown
- Periodically clean stale app directories whose alive lock is no longer held
- Treat PID 0 in scan results as a data-integrity warning worth alerting on
When it happens
Trigger: A live-lock-holding app directory contains a bus.pid whose trimmed content has fewer than two newline-separated lines — e.g. empty file, single-line file, or a file truncated/corrupted by a crash between creation and the atomic rename of an older writer.
Common situations: Manual edits or truncation of bus.pid, a crash or kill before any successful rename completed, disk corruption, or a third-party tool rewriting the file in an unexpected format.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- busdiscover: malformed pid in %s: %w
- busdiscover: mkdir %s: %w
- busdiscover: write pid tmp: %w
- busdiscover: rename pid file: %w
- busdiscover: malformed timestamp in %s: %w
AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04).
Data as JSON: /api/errors/5625ea249f69beb8.
Report an issue: GitHub.