Skip to content

Commit 10c95bc

Browse files
committed
Runtime API: Clean up lock file on chrome hard-kill
1 parent 587b27f commit 10c95bc

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

server/headless.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"encoding/json"
66
"fmt"
77
"log"
8+
"os"
9+
"path/filepath"
810
"strings"
911
"sync"
1012
"time"
@@ -92,6 +94,12 @@ func (hb *HeadlessBrowser) launch() error {
9294
}
9395

9496
if hb.config.UserDataDir != "" {
97+
// Remove stale lock file left behind if the server was hard-killed.
98+
// Chrome refuses to start when a SingletonLock exists from a dead process.
99+
lockFile := filepath.Join(hb.config.UserDataDir, "SingletonLock")
100+
if err := os.Remove(lockFile); err == nil {
101+
log.Println("[Headless] Removed stale Chrome lock file")
102+
}
95103
opts = append(opts, chromedp.UserDataDir(hb.config.UserDataDir))
96104
log.Printf("[Headless] Using persistent Chrome profile: %s", hb.config.UserDataDir)
97105
}

0 commit comments

Comments
 (0)