Repository navigation
guard: fix flaky lapse test (EINTR, fake daemon fd reuse); doctor: assurance for new sessions - #1
Merged
Merged
Conversation
…anent The test read the daemon's protect count right after seeing the lapse, but check marks the lapse before it sends the new protect request. Wait for the request and for a later confirmed check instead of sleeping. Stressing it also showed Protect failing with "interrupted system call": the client socket has SO_RCVTIMEO/SO_SNDTIMEO, so recvmsg and sendmsg return EINTR on a signal even with SA_RESTART, and the Go runtime sends SIGURG to preempt goroutines. WriteMsg and ReadMsg now retry on EINTR (a SOCK_SEQPACKET message is sent whole or not at all). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The summary printed only the layer 2 level ("confined") even with
cotty-guard running. It now also names the level a session created now
can reach (strong with the guard running, confined without it, weak with
a replaceable binary) and notes that sessions created before the guard
started keep their level. --json gains sessions and sessions_note.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fake daemon in the session tests closed its sockets while its accept and connection goroutines could still be about to use them. A goroutine of a stopped fake then read from the descriptor number the next test's connection reused, took the session's protect request and counted it on the old fake: TestSessionLapseIsPermanent timed out waiting for it. stop now shuts the sockets down, waits for the goroutines and only then closes the descriptors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Flaky
TestSessionLapseIsPermanentStressing it turned up three causes:
checkmarks the lapse before it sends the new protect request, so the test could read the daemon's protect count too early. The test now waits for the request, then for a later check the daemon confirms. Then it asserts the session is notstrong. No fixed sleeps.SO_RCVTIMEO/SO_SNDTIMEO, sorecvmsg/sendmsgreturn EINTR on a signal even with SA_RESTART (signal(7)). The Go runtime sends SIGURG for preemption, soProtectcould fail with "interrupted system call".WriteMsg/ReadMsgnow retry on EINTR. Resending is safe because a SOCK_SEQPACKET message is sent whole or not at all.stop()closed sockets while the fake's goroutines could still use them. A stale goroutine then read from the descriptor number reused by the next test's connection and took the session's protect request.stop()now shuts the sockets down, waits for the goroutines, then closes them.Verification (host, unit only):
go test ./internal/guard -run TestSessionLapseIsPermanent -count=1000 -cpu 1,2,4: passgo test -race -count=3 ./internal/guard: passCGO_ENABLED=0 go build ./...,go vet ./...,gofmt -l .,go test ./...: cleancotty doctorsummaryBefore, the summary printed only the layer 2 level (
confined) even with cotty-guard running. It now prints that level, labelled as layer 2, and adds a line for new sessions:strong available for new sessions (cotty-guard running), with a note that sessions created before the guard started stay at their levelconfined (cotty-guard not running)/(cotty-guard not answering)weakwhen the cotty binary can be replaced by the user,unavailablewithout user namespaces--jsongainssessionsandsessions_note;assurancekeeps its meaning. A unit test coverssessionsSummary, and docs/confinement.md describes the new line.🤖 Generated with Claude Code