Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix: treat profile lock as stale when pinchtab pid is alive but no chrome uses the profile

Luigi Agostie488110a9bd9
diff --git a/internal/bridge/profile_lock.go b/internal/bridge/profile_lock.go
index ba962d66..ddde5d85 100644
--- a/internal/bridge/profile_lock.go
+++ b/internal/bridge/profile_lock.go
@@ -27,6 +27,7 @@ var chromeProfileProcessLister = findChromeProfileProcesses
var chromePIDIsRunning = isChromePIDRunning
var killChromeProfileProcesses = killProcesses
var isProfileOwnedByRunningPinchtabMock = isProfileOwnedByRunningPinchtab
+var isPinchTabProcessFunc = isPinchTabProcess
var chromeSingletonFiles = []string{
"SingletonLock",
@@ -138,7 +139,17 @@ func isProfileOwnedByRunningPinchtab(profileDir string) (bool, int) {
if err == nil && running {
// Even if the PID is running, check if it's actually a pinchtab process
// to handle PID reuse.
- if isPinchTabProcess(pid) {
+ if isPinchTabProcessFunc(pid) {
+ processes, procErr := chromeProfileProcessLister(profileDir)
+ if procErr == nil && len(processes) == 0 {
+ slog.Debug("pinchtab pid file points to a running pinchtab but no chrome is using the profile; treating lock as stale",
+ "profile", profileDir, "pid", pid)
+ return false, 0
+ }
+ if procErr != nil {
+ slog.Debug("unable to verify chrome ownership for running pinchtab pid; keeping profile locked",
+ "profile", profileDir, "pid", pid, "err", procErr)
+ }
slog.Debug("profile is owned by another active pinchtab", "profile", profileDir, "pid", pid)
return true, pid
}
diff --git a/internal/bridge/profile_lock_test.go b/internal/bridge/profile_lock_test.go
index e79100fa..bebd7e63 100644
--- a/internal/bridge/profile_lock_test.go
+++ b/internal/bridge/profile_lock_test.go
@@ -165,3 +165,55 @@ func TestClearStaleChromeProfileLockFallsBackToPIDProbe(t *testing.T) {
t.Fatalf("expected lock file to be removed, got err=%v", err)
}
}
+
+func TestIsProfileOwnedByRunningPinchtabTreatsPinchTabPIDWithoutChromeAsStale(t *testing.T) {
+ profileDir := t.TempDir()
+ if err := os.WriteFile(filepath.Join(profileDir, "pinchtab.pid"), []byte("1234"), 0644); err != nil {
+ t.Fatalf("write pid file: %v", err)
+ }
+
+ origPID := chromePIDIsRunning
+ origPinchTab := isPinchTabProcessFunc
+ origLister := chromeProfileProcessLister
+ t.Cleanup(func() {
+ chromePIDIsRunning = origPID
+ isPinchTabProcessFunc = origPinchTab
+ chromeProfileProcessLister = origLister
+ })
+
+ chromePIDIsRunning = func(pid int) (bool, error) { return pid == 1234, nil }
+ isPinchTabProcessFunc = func(pid int) bool { return pid == 1234 }
+ chromeProfileProcessLister = func(path string) ([]chromeProfileProcess, error) { return nil, nil }
+
+ owned, _ := isProfileOwnedByRunningPinchtab(profileDir)
+ if owned {
+ t.Fatal("expected stale pinchtab pid with no chrome to be treated as not owned")
+ }
+}
+
+func TestIsProfileOwnedByRunningPinchtabKeepsLockWhenChromeUsesProfile(t *testing.T) {
+ profileDir := t.TempDir()
+ if err := os.WriteFile(filepath.Join(profileDir, "pinchtab.pid"), []byte("1234"), 0644); err != nil {
+ t.Fatalf("write pid file: %v", err)
+ }
+
+ origPID := chromePIDIsRunning
+ origPinchTab := isPinchTabProcessFunc
+ origLister := chromeProfileProcessLister
+ t.Cleanup(func() {
+ chromePIDIsRunning = origPID
+ isPinchTabProcessFunc = origPinchTab
+ chromeProfileProcessLister = origLister
+ })
+
+ chromePIDIsRunning = func(pid int) (bool, error) { return pid == 1234, nil }
+ isPinchTabProcessFunc = func(pid int) bool { return pid == 1234 }
+ chromeProfileProcessLister = func(path string) ([]chromeProfileProcess, error) {
+ return []chromeProfileProcess{{PID: "99", Command: "/usr/bin/chromium --user-data-dir=" + path}}, nil
+ }
+
+ owned, pid := isProfileOwnedByRunningPinchtab(profileDir)
+ if !owned || pid != 1234 {
+ t.Fatalf("expected profile with active chrome to stay locked, got owned=%v pid=%d", owned, pid)
+ }
+}