Release the shared config lock before logging PBS poll scope (#5430)

PBS poll setup logged its copied configuration while holding the shared
config read lock. If the log sink stalled, configuration writers could
not proceed; once a writer waited, unrelated configuration readers could
queue as well. Log the same copied snapshot after unlocking.

Contract-Neutral: Preserve the PBS snapshot and copied datastore
exclusions, log event and fields, polling admission, and all published
outcomes; only the lock lifetime around diagnostic I/O changes.

---
Fleet candidate `20261128T175023Z-core-runtime` from the `core-runtime`
lane. Reviewed tip `4588f52fbbea87db72bc1424cee52e98489e9409` on `main`.

[How Pulse handles
triage](https://github.com/rcourtman/Pulse/blob/main/docs/AI_TRANSPARENCY.md)
This commit is contained in:
pulse-triage[bot]
2026-11-28 19:09:22 +00:00
committed by GitHub
2 changed files with 91 additions and 6 deletions

View File

@@ -361,12 +361,6 @@ func (m *Monitor) pollPBSInstance(ctx context.Context, instanceName string, clie
snapshot := cfg
snapshot.ExcludeDatastores = append([]string(nil), cfg.ExcludeDatastores...)
instanceCfg = &snapshot
if debugEnabled {
log.Debug().
Str("instance", instanceName).
Bool("monitorDatastores", snapshot.MonitorDatastores).
Msg("Found PBS instance config")
}
break
}
}
@@ -377,6 +371,14 @@ func (m *Monitor) pollPBSInstance(ctx context.Context, instanceName string, clie
log.Error().Str("instance", instanceName).Msg("PBS instance config not found")
return
}
// A slow log sink must not hold the shared config lock. The diagnostic
// describes the same snapshot that this poll will use.
if debugEnabled {
log.Debug().
Str("instance", instanceName).
Bool("monitorDatastores", instanceCfg.MonitorDatastores).
Msg("Found PBS instance config")
}
if instanceCfg.Disabled {
skipped = true
if debugEnabled {

View File

@@ -1,6 +1,7 @@
package monitoring
import (
"bytes"
"context"
"encoding/json"
"net/http"
@@ -15,8 +16,90 @@ import (
"github.com/rcourtman/pulse-go-rewrite/internal/models"
"github.com/rcourtman/pulse-go-rewrite/pkg/pbs"
"github.com/rcourtman/pulse-go-rewrite/pkg/pmg"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
type blockedPBSConfigLog struct {
enter func()
release <-chan struct{}
}
func (w blockedPBSConfigLog) Write(p []byte) (int, error) {
if bytes.Contains(p, []byte("Found PBS instance config")) &&
bytes.Contains(p, []byte(`"instance":"pbs-held"`)) {
w.enter()
<-w.release
}
return len(p), nil
}
func TestPollPBSConfigLoggingDoesNotBlockConfigEditOrPeerPoll(t *testing.T) {
held, peer := newPBSHealthTestServer(t), newPBSHealthTestServer(t)
m := newPBSHealthAuthorityMonitor([]config.PBSInstance{
{Name: "pbs-held", Host: held.server.URL, MonitorDatastores: true, ExcludeDatastores: []string{"backups"}},
{Name: "pbs-peer", Host: peer.server.URL, MonitorDatastores: true},
})
heldClient := newPBSHealthTestClient(t, held.server.URL)
peerClient := newPBSHealthTestClient(t, peer.server.URL)
// The package logger is shared; don't run this test in parallel.
original, originalLevel := log.Logger, zerolog.GlobalLevel()
entered, release, done := make(chan struct{}), make(chan struct{}), make(chan struct{})
unblock := sync.OnceFunc(func() { close(release) })
log.Logger = zerolog.New(blockedPBSConfigLog{sync.OnceFunc(func() { close(entered) }), release}).Level(zerolog.DebugLevel)
zerolog.SetGlobalLevel(zerolog.DebugLevel)
defer func() {
unblock()
<-done
log.Logger = original
zerolog.SetGlobalLevel(originalLevel)
}()
go func() {
defer close(done)
m.pollPBSInstance(t.Context(), "pbs-held", heldClient)
}()
select {
case <-entered:
case <-done:
t.Fatal("poll returned before its config diagnostic")
case <-time.After(5 * time.Second):
t.Fatal("poll did not reach its config diagnostic")
}
// There is no other config user in this fixture. TryLock makes a failure
// deterministic and lets teardown release the diagnostic before joining.
if !config.Mu.TryLock() {
t.Fatal("blocked PBS config diagnostic held the shared config lock against writers")
}
// Change the existing backing array to verify the admitted poll owns its
// copied exclusions, rather than reusing a slice from the live config.
m.config.PBSInstances[0].ExcludeDatastores[0] = "other"
config.Mu.Unlock()
m.pollPBSInstance(t.Context(), "pbs-peer", peerClient)
state := m.state.GetSnapshot()
observed := pbsInstanceByName(t, state, "pbs-peer")
if len(state.PBSInstances) != 1 || observed.Status != "online" ||
len(observed.Datastores) != 1 || observed.Datastores[0].Name != "backups" {
t.Fatalf("while first diagnostic was blocked, want only the peer online with backups: %+v", state.PBSInstances)
}
t.Log("while diagnostic was blocked: config edit completed and independent PBS poll published online with backups")
unblock()
<-done
observed = pbsInstanceByName(t, m.state.GetSnapshot(), "pbs-held")
if observed.Status != "online" || len(observed.Datastores) != 0 {
t.Fatalf("released poll did not retain the original exclusion: %+v", observed)
}
m.pollPBSInstance(t.Context(), "pbs-held", heldClient)
observed = pbsInstanceByName(t, m.state.GetSnapshot(), "pbs-held")
if observed.Status != "online" || len(observed.Datastores) != 1 || observed.Datastores[0].Name != "backups" {
t.Fatalf("next poll did not use the edited exclusion: %+v", observed)
}
t.Log("after release: admitted poll preserved its original exclusion; next poll picked up the edit")
}
func TestPollPBSInstancePausedDoesNotFabricateSuccess(t *testing.T) {
var hits atomic.Int32
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {