fix(web): re-read pidFile before validating pico token
When the gateway process crashes and restarts, the backend caches the old pidData (PID, token). If the WebSocket proxy handler uses stale pidData, picoComposedToken returns an empty string causing "Invalid Pico token" errors. ReadPidFileWithCheck validates that the process is still alive and returns fresh data if the gateway restarted, so always re-read the pidFile before token validation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
1ad94ffb34
commit
2701037efb
1 changed files with 7 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
"github.com/sipeed/picoclaw/pkg/config"
|
||||
"github.com/sipeed/picoclaw/pkg/logger"
|
||||
ppid "github.com/sipeed/picoclaw/pkg/pid"
|
||||
)
|
||||
|
||||
// registerPicoRoutes binds Pico Channel management endpoints to the ServeMux.
|
||||
|
|
@ -56,6 +57,12 @@ func (h *Handler) createWsProxy(origProtocol string, token string) *httputil.Rev
|
|||
func (h *Handler) handleWebSocketProxy() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
gateway.mu.Lock()
|
||||
// Re-read pidFile to detect if gateway restarted with new credentials.
|
||||
// ReadPidFileWithCheck also validates the process is still alive.
|
||||
if newPidData := ppid.ReadPidFileWithCheck(globalConfigDir()); newPidData != nil {
|
||||
gateway.pidData = newPidData
|
||||
refreshPicoTokensLocked(h.configPath)
|
||||
}
|
||||
ensurePicoTokenCachedLocked(h.configPath)
|
||||
gatewayAvailable := gateway.pidData != nil
|
||||
gateway.mu.Unlock()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue