diff --git a/seaweed-block/core/transport/recovery_sink_adapter.go b/seaweed-block/core/transport/recovery_sink_adapter.go index 06da25a4ab..26be2d6d95 100644 --- a/seaweed-block/core/transport/recovery_sink_adapter.go +++ b/seaweed-block/core/transport/recovery_sink_adapter.go @@ -61,6 +61,20 @@ type RecoverySink struct { // NewRecoverySink ensures the WalShipperEntry exists (via // WalShipperFor) so the emit-context update in StartSession has // somewhere to land. +// +// Caller obligations: +// +// - Defer EndSession at the call site that calls StartSession. +// If StartSession returns an error, the emit context has already +// been swapped to session — only the deferred EndSession restores +// steady. (recovery.Sender.Run defers sink.EndSession; production +// callers using NewRecoverySink directly must do the same.) +// - The caller is responsible for snapshotting the steady context +// correctly. Passing nil sessionConn is a programmer error +// (Realtime emits during the session would have nowhere to go); +// passing nil steadyConn is honest only when no steady ship was +// in flight before this session — the next steady emit will see +// "no conn" and fail closed at the EmitFunc level. func NewRecoverySink( e *BlockExecutor, replicaID string, diff --git a/seaweed-block/core/transport/recovery_sink_adapter_test.go b/seaweed-block/core/transport/recovery_sink_adapter_test.go index bd9b305361..d248f357d4 100644 --- a/seaweed-block/core/transport/recovery_sink_adapter_test.go +++ b/seaweed-block/core/transport/recovery_sink_adapter_test.go @@ -49,6 +49,13 @@ type recordedEmit struct { // // Returns a pointer to a slice the test consumes; callers must // hold the test's mutex while reading. +// +// TEST-ONLY / single-goroutine: the entry.shipper assignment below +// does NOT acquire walShipperMu. Production paths (WalShipperFor, +// updateWalShipperEmitContext) take that mutex; this helper bypasses +// it deliberately because tests run before any concurrent access. +// Do not lift this pattern into production code or concurrent test +// scenarios without re-introducing the lock. func installRecordingShipper(t *testing.T, e *BlockExecutor, replicaID string) (*[]recordedEmit, *sync.Mutex) { t.Helper()