{"record":{"id":"089dabf3ecc5407d","repo":"chenhg5/cc-connect","slug":"another-cc-connect-instance-is-already-running-wit-089dab","errorCode":null,"errorMessage":"another cc-connect instance is already running with config %s","messagePattern":"another cc-connect instance is already running with config (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/instance_lock_windows.go","lineNumber":54,"sourceCode":"\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\nfunc (l *InstanceLock) Release() {\n\tif l == nil || !l.acquired {","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/instance_lock_windows.go#L36-L72","documentation":"Windows lock-contention fallback: CreateFile failed but readPIDFromLockFile could not recover a positive PID (empty/corrupt lock file), so the error reports only the config path. It still means the lock file cannot be opened for exclusive use — another instance or an OS-level file problem.","triggerScenarios":"syscall.CreateFile returns an error on the lock path and readPIDFromLockFile returns <= 0; could be sharing violation from another process or an access-denied/invalid-path condition.","commonSituations":"Previous instance crashed before writing its PID; lock file created by another user (access denied); antivirus or sync tool holding the file open.","solutions":["Check the actual Win32 error behind createErr in logs — sharing violation means a live holder, access denied means permissions.","Identify the holder (Resource Monitor / handle.exe on the lock file) and stop it if it is a cc-connect process.","Delete the stale lock file if no process holds it.","Check ACLs on the config directory (icacls) if the error is access-denied rather than sharing-violation."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"lock, err := AcquireInstanceLock(configPath)\nif err != nil && strings.HasPrefix(err.Error(), \"another cc-connect instance is already running\") {\n    // PID unknown on Windows — check the lock file with handle.exe/Resource Monitor\n    fmt.Fprintln(os.Stderr, \"lock held by unknown process; inspect\", lockPath)\n    os.Exit(1)\n}","preventionTips":["Check icacls on the config dir when this recurs without a running instance.","Exclude the config dir from antivirus/OneDrive sync locking.","Delete stale lock files only after confirming no holder."],"tags":["windows","singleton","file-lock","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-14T05:17:10.506Z"}