chenhg5/cc-connect · error

another cc-connect instance is already running (PID %d) with

Error message

another cc-connect instance is already running (PID %d) with config %s

What it means

Windows variant of lock contention: syscall.CreateFile on the lock file failed and readPIDFromLockFile recovered a positive PID, so this error names the running instance's PID and config path. CreateFile fails when another instance holds the lock with no share/write access, or on permission problems — but the intent of the message is "another instance is running".

Source

Thrown at cmd/cc-connect/instance_lock_windows.go:52

	pathPtr, err := syscall.UTF16PtrFromString(lockPath)
	if err != nil {
		return nil, fmt.Errorf("cannot convert lock path: %w", err)
	}

	handle, createErr := syscall.CreateFile(
		pathPtr,
		syscall.GENERIC_READ|syscall.GENERIC_WRITE,
		syscall.FILE_SHARE_READ,
		nil,
		syscall.OPEN_ALWAYS,
		syscall.FILE_ATTRIBUTE_NORMAL,
		0,
	)

	if createErr != nil {
		pid := readPIDFromLockFile(lockPath)
		if pid > 0 {
			return nil, fmt.Errorf("another cc-connect instance is already running (PID %d) with config %s", pid, configPath)
		}
		return nil, fmt.Errorf("another cc-connect instance is already running with config %s", configPath)
	}

	pid := os.Getpid()
	syscall.SetFilePointer(handle, 0, nil, syscall.FILE_BEGIN)
	syscall.SetEndOfFile(handle)
	var written uint32
	syscall.WriteFile(handle, []byte(fmt.Sprintf("%d\n", pid)), &written, nil)
	syscall.FlushFileBuffers(handle)

	return &InstanceLock{
		handle:   handle,
		path:     lockPath,
		acquired: true,
	}, nil
}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Confirm the PID is live (tasklist /FI "PID eq <PID>") and stop the existing instance (taskkill /PID <PID> or stop the service).
  2. Use a different --config path if a genuinely independent instance is required.
  3. If the PID is stale, delete the lock file and retry.
Defensive patterns

Strategy: try-catch

Try / catch

lock, err := AcquireInstanceLock(configPath)
if err != nil {
    var pid int
    if _, scanErr := fmt.Sscanf(err.Error(), "another cc-connect instance is already running (PID %d)", &pid); scanErr == nil {
        fmt.Fprintf(os.Stderr, "stop PID %d first.\n", pid)
    }
    os.Exit(1)
}

Prevention

When it happens

Trigger: AcquireInstanceLock on Windows while another cc-connect process holds an open handle (created without FILE_SHARE_WRITE) on <configDir>\. <configBase>.lock and its PID was read back successfully.

Common situations: Second launch while the service/scheduled-task instance is running; running under a different user while the first instance's handle denies sharing.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/bdef8c3879cd01a0. Report an issue: GitHub.