fix(pier): an ended session is never written back by a request still in flight

- persisting a session's protocol state after a request now rewrites an
  existing record only (Redis SET XX, the memory store likewise) and closes
  the local copy when the record is gone
- before, a request that finished after DELETE, a revoked or deleted subject
  event or the idle expiry put the record back, and the next request
  rehydrated the ended session
- found by plan 19.7-05's TestFanOut (revocation and deletion cases, about
  one run in a hundred)
This commit is contained in:
Jakub Zych
2026-10-23 13:55:04 +02:00
parent c29d2289d0
commit 1111828e8a
4 changed files with 69 additions and 1 deletions

View File

@@ -52,6 +52,19 @@ func (m *memoryStore) Get(_ context.Context, id string) (Record, bool, error) {
return r.rec, true, nil
}
// Update rewrites an existing record; a missing or expired one stays gone.
func (m *memoryStore) Update(_ context.Context, id string, rec Record, ttl time.Duration) (bool, error) {
m.mu.Lock()
defer m.mu.Unlock()
r, ok := m.records[id]
if !ok || !r.expires.After(m.now()) {
delete(m.records, id)
return false, nil
}
m.records[id] = memoryRecord{rec: rec, expires: m.now().Add(ttl)}
return true, nil
}
func (m *memoryStore) Touch(_ context.Context, id string, ttl time.Duration) error {
m.mu.Lock()
defer m.mu.Unlock()