2.7 KiB
Cremote Daemon Crash - Rod Library Nil Map Panic
Error Summary
The daemon crashed with a panic: assignment to entry in nil map in the rod library's setHelper function.
Root Cause
This is a known issue in the go-rod library (see https://github.com/go-rod/rod/issues/331).
When pages are retrieved using browser.Pages(), the returned *rod.Page objects are not fully initialized. Specifically, internal maps (like the helper map used for JavaScript evaluation) are nil. When methods like WaitLoad() try to use these pages, they attempt to write to nil maps, causing a panic.
This typically happens when:
- The daemon is restarted but the browser is still running with existing tabs
- A tab is created outside of the daemon
- A tab was removed from the cache but still exists in the browser
Stack Trace
headlesschromium | panic: assignment to entry in nil map
headlesschromium |
headlesschromium | goroutine 466 [running]:
headlesschromium | github.com/go-rod/rod.(*Page).setHelper(0x95fc61?, {0xc000156888?, 0x935bc0?}, {0x9553a2, 0x8}, {0xc0003aa1b0, 0x17})
headlesschromium | /root/go/pkg/mod/github.com/go-rod/rod@v0.116.2/page_eval.go:320 +0xdf
headlesschromium | github.com/go-rod/rod.(*Page).ensureJSHelper(0xc00013e2c0, 0xf70e80)
headlesschromium | /root/go/pkg/mod/github.com/go-rod/rod@v0.116.2/page_eval.go:292 +0x47c
headlesschromium | github.com/go-rod/rod.(*Page).WaitLoad(0xc00013e2c0)
headlesschromium | /root/go/pkg/mod/github.com/go-rod/rod@v0.116.2/page.go:858 +0x1a5
headlesschromium | git.teamworkapps.com/shortcut/cremote/daemon.(*Daemon).loadURL.func1()
headlesschromium | /tmp/cremote/daemon/daemon.go:2532 +0x9d
Fix Applied
Modified daemon/daemon.go in the findPageByID function to:
- Initialize pages properly: Call
p.Info()on pages retrieved frombrowser.Pages()to ensure internal state is initialized - Add error handling: Return an error if initialization fails instead of trying to use an uninitialized page
- Add panic recovery: Use defer/recover to catch any panics during initialization
- Improve caching: When a page is found and cached, also set up console logging for it
- Add debug logging: Log when pages are found and cached from the browser
Code Changes
See daemon/daemon.go lines 2363-2400 and 2428-2448.
Testing
The code compiles successfully. The fix should prevent the panic by ensuring pages are properly initialized before use.
Prevention
To avoid this issue in the future:
- Always create tabs through the daemon's
openTabfunction - Avoid manually creating tabs in the browser when the daemon is running
- If the daemon is restarted, consider closing all existing browser tabs first