Explorar el Código

fix(rtlconsole): return a copy of the cached entry from snapshot (#1168)

snapshot copied the entry pointer under the lock, unlocked, and then
read out.Firmware; the background poll writes the same fields under the
lock, tripping the race detector and possibly handing a half-updated
entry to the beacon payload. Copy the value under the lock and return a
pointer to the copy so every read after the unlock is race-free.

Closes #1167
Nacho hace 2 meses
padre
commit
22c69b0cc2
Se han modificado 1 ficheros con 4 adiciones y 2 borrados
  1. 4 2
      server-go/internal/httpapi/rtlconsole.go

+ 4 - 2
server-go/internal/httpapi/rtlconsole.go

@@ -90,12 +90,14 @@ func (c *rtlConsoleCache) snapshot(slug, host string) *rtlConsoleEntry {
 		go c.poll(slug, host)
 		c.mu.Lock()
 	}
-	out := e
+	// Copia bajo el lock: el caller lee los campos ya fuera del mutex y el
+	// poll en background los puede estar escribiendo en paralelo (#1167).
+	out := *e
 	c.mu.Unlock()
 	if out.Firmware == "" {
 		return nil
 	}
-	return out
+	return &out
 }
 
 // invalidate marca la entrada para re-poll inmediato (reboot detectado por el