{"record":{"id":"bdef8c3879cd01a0","repo":"chenhg5/cc-connect","slug":"another-cc-connect-instance-is-already-running-pi-bdef8c","errorCode":null,"errorMessage":"another cc-connect instance is already running (PID %d) with config %s","messagePattern":"another cc-connect instance is already running \\(PID (.+?)\\) with config (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/instance_lock_windows.go","lineNumber":52,"sourceCode":"\tpathPtr, err := syscall.UTF16PtrFromString(lockPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"cannot convert lock path: %w\", err)\n\t}\n\n\thandle, createErr := syscall.CreateFile(\n\t\tpathPtr,\n\t\tsyscall.GENERIC_READ|syscall.GENERIC_WRITE,\n\t\tsyscall.FILE_SHARE_READ,\n\t\tnil,\n\t\tsyscall.OPEN_ALWAYS,\n\t\tsyscall.FILE_ATTRIBUTE_NORMAL,\n\t\t0,\n\t)\n\n\tif createErr != nil {\n\t\tpid := readPIDFromLockFile(lockPath)\n\t\tif pid > 0 {\n\t\t\treturn nil, fmt.Errorf(\"another cc-connect instance is already running (PID %d) with config %s\", pid, configPath)\n\t\t}\n\t\treturn nil, fmt.Errorf(\"another cc-connect instance is already running with config %s\", configPath)\n\t}\n\n\tpid := os.Getpid()\n\tsyscall.SetFilePointer(handle, 0, nil, syscall.FILE_BEGIN)\n\tsyscall.SetEndOfFile(handle)\n\tvar written uint32\n\tsyscall.WriteFile(handle, []byte(fmt.Sprintf(\"%d\\n\", pid)), &written, nil)\n\tsyscall.FlushFileBuffers(handle)\n\n\treturn &InstanceLock{\n\t\thandle:   handle,\n\t\tpath:     lockPath,\n\t\tacquired: true,\n\t}, nil\n}\n","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/instance_lock_windows.go#L34-L70","documentation":"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\".","triggerScenarios":"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.","commonSituations":"Second launch while the service/scheduled-task instance is running; running under a different user while the first instance's handle denies sharing.","solutions":["Confirm the PID is live (tasklist /FI \"PID eq <PID>\") and stop the existing instance (taskkill /PID <PID> or stop the service).","Use a different --config path if a genuinely independent instance is required.","If the PID is stale, delete the lock file and retry."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"lock, err := AcquireInstanceLock(configPath)\nif err != nil {\n    var pid int\n    if _, scanErr := fmt.Sscanf(err.Error(), \"another cc-connect instance is already running (PID %d)\", &pid); scanErr == nil {\n        fmt.Fprintf(os.Stderr, \"stop PID %d first.\\n\", pid)\n    }\n    os.Exit(1)\n}","preventionTips":["Run instances via Windows services or scheduled tasks that enforce singletons.","Always use the same user account for the daemon.","Use distinct config paths for parallel instances."],"tags":["windows","singleton","file-lock","process","cli"],"backgroundTag":"instance-already-running","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}