wavetermdev/waveterm · error

cannot create stderr pipe: %w

Error message

cannot create stderr pipe: %w

What it means

Returned when creating the stderr pipe for a spawned job fails, an OS resource-limit condition. The underlying error is wrapped with %w.

Source

Thrown at pkg/wshrpc/wshremote/wshremote_job.go:167

	defer readyPipeRead.Close()
	defer readyPipeWrite.Close()

	cmd := exec.Command(wshPath, "jobmanager", "--jobid", data.JobId, "--clientid", data.ClientId)
	if data.PublicKeyBase64 != "" {
		cmd.Env = append(os.Environ(), "WAVETERM_PUBLICKEY="+data.PublicKeyBase64)
	}
	cmd.ExtraFiles = []*os.File{readyPipeWrite}
	stdin, err := cmd.StdinPipe()
	if err != nil {
		return nil, fmt.Errorf("cannot create stdin pipe: %w", err)
	}
	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return nil, fmt.Errorf("cannot create stdout pipe: %w", err)
	}
	stderr, err := cmd.StderrPipe()
	if err != nil {
		return nil, fmt.Errorf("cannot create stderr pipe: %w", err)
	}
	log.Printf("RemoteStartJobCommand: created pipes\n")

	if err := cmd.Start(); err != nil {
		return nil, fmt.Errorf("cannot start job manager: %w", err)
	}
	readyPipeWrite.Close()
	log.Printf("RemoteStartJobCommand: job manager process started\n")

	jobAuthTokenLine := fmt.Sprintf("Wave-JobAccessToken:%s\n", data.JobAuthToken)
	if _, err := stdin.Write([]byte(jobAuthTokenLine)); err != nil {
		cmd.Process.Kill()
		return nil, fmt.Errorf("cannot write job auth token: %w", err)
	}
	stdin.Close()
	log.Printf("RemoteStartJobCommand: wrote auth token to stdin\n")

	go func() {

View on GitHub (pinned to a4447c1563)

Solutions

  1. Audit and fix fd leaks (all pipes/streams per job must be closed)
  2. Raise RLIMIT_NOFILE for the server process
  3. Restart the process to reclaim descriptors
Defensive patterns

Strategy: try-catch

Validate before calling

var lim syscall.Rlimit
syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim)
if lim.Cur < 1024 {
    return fmt.Errorf("fd limit too low")
}

Try / catch

rtn, err := server.RemoteStartJobCommand(ctx, data)
if err != nil {
    if strings.Contains(err.Error(), "cannot create stderr pipe") {
        // fd exhaustion; fix leaks or raise limits before retry
    }
    return err
}

Prevention

When it happens

Trigger: Calling RemoteStartJobCommand when fd allocation fails right before cmd.Start().

Common situations: fd exhaustion on hosts running many concurrent jobs or leaking descriptors over time.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/fbbb5c74d85ddea8. Report an issue: GitHub.