test / test (push) Canceled after 0s
Neither review (read-only agents, Opus and Fable, over ae06d8b..815236a) has a Critical or High finding. What they found and what was done: - A stranger on port 25 could grow the table: every queue-id line of inbound mail was stored and pruned an hour or more later, his own message-id among them. The tailer now leaves out the lines of a queue id that postfix/inbound/smtpd opened, until qmgr removes the message or another listener opens one under the id; 4096 such ids are remembered. - A commit, so a disk sync, per stored line on the connection the journal milter shares, and a backlog written line by line. Lines are now written in one transaction per pass over the log, 500 at most, before the read offset is saved (InsertSendLogLines; follow() calls the keeper's flush). - The prune asked the send log once per line and ran hourly. It asks once per queue id and runs at start and with the six-hourly sweep; with port-25 mail left out there is little without a row to wait for. - The 4096-byte cut could split a character; it keeps characters whole. - security.md did not say that a backup now carries these lines, and the plan said the time window excludes a reused queue id where it only limits the chance to the row's queue lifetime. Both are corrected; the collision is recorded as an accepted risk with its trigger. - Tests that did not prove their comments: the prune is now tested with the sweep, a rejected row next to the prune, batching and the change from catching up to following, port-25 mail left out and its id reused. Left as found and written down in the plan: lines the tailer never reads (a file rotated away while the panel was down), and a message in the queue across the upgrade, which shows only its later lines. On the test server, for this tree: go vet clean, go test ./... 22 packages ok, make e2e ok. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
90 lines
2.3 KiB
Go
90 lines
2.3 KiB
Go
package logtail
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/mixeme/selfpost/internal/store"
|
|
)
|
|
|
|
type retentionProbeStore struct {
|
|
mu sync.Mutex
|
|
cutoff time.Time
|
|
}
|
|
|
|
func (s *retentionProbeStore) UpdateStatus(string, string, string) (int64, error) {
|
|
return 0, nil
|
|
}
|
|
|
|
func (s *retentionProbeStore) ListQueuedOlderThan(time.Time) ([]store.QueuedDelivery, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (s *retentionProbeStore) DeleteSendLogBefore(cutoff time.Time) (int64, error) {
|
|
s.mu.Lock()
|
|
s.cutoff = cutoff
|
|
s.mu.Unlock()
|
|
return 0, nil
|
|
}
|
|
|
|
func (s *retentionProbeStore) InsertSendLogLines([]store.SendLogLine, bool) (int, error) {
|
|
return 0, nil
|
|
}
|
|
|
|
func (s *retentionProbeStore) PruneSendLogLines(time.Time) (int64, error) { return 0, nil }
|
|
|
|
func (s *retentionProbeStore) LogtailState(string) (store.LogtailState, bool, error) {
|
|
return store.LogtailState{}, false, nil
|
|
}
|
|
|
|
func (s *retentionProbeStore) SaveLogtailState(string, store.LogtailState) error {
|
|
return nil
|
|
}
|
|
|
|
func (s *retentionProbeStore) lastCutoff() time.Time {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
return s.cutoff
|
|
}
|
|
|
|
// retentionLoop must re-read the configured window every cycle so a panel
|
|
// change takes effect without restarting the process.
|
|
func TestRetentionLoopUsesUpdatedValue(t *testing.T) {
|
|
old := retentionInterval
|
|
retentionInterval = 20 * time.Millisecond
|
|
t.Cleanup(func() { retentionInterval = old })
|
|
|
|
var days atomic.Int32
|
|
days.Store(30)
|
|
|
|
st := &retentionProbeStore{}
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
go retentionLoop(ctx, st, func() int { return int(days.Load()) })
|
|
|
|
deadline := time.Now().Add(2 * time.Second)
|
|
for time.Now().Before(deadline) {
|
|
if age := time.Since(st.lastCutoff()); age < 31*24*time.Hour && age > 29*24*time.Hour {
|
|
break
|
|
}
|
|
time.Sleep(5 * time.Millisecond)
|
|
}
|
|
if age := time.Since(st.lastCutoff()); age < 29*24*time.Hour || age > 31*24*time.Hour {
|
|
t.Fatalf("first prune cutoff age %v, want about 30 days", age)
|
|
}
|
|
|
|
days.Store(7)
|
|
deadline = time.Now().Add(2 * time.Second)
|
|
for time.Now().Before(deadline) {
|
|
if age := time.Since(st.lastCutoff()); age < 8*24*time.Hour && age > 6*24*time.Hour {
|
|
return
|
|
}
|
|
time.Sleep(5 * time.Millisecond)
|
|
}
|
|
age := time.Since(st.lastCutoff())
|
|
t.Fatalf("second prune cutoff age %v, want about 7 days", age)
|
|
}
|