Reduce session expiry scans and add an optional admission cap - #407
Merged
Merged
Conversation
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.
Closes #396.
Changes
Session.Closeunregisters immediately.Jaws.MaxSessionscap. Admission refuses new Sessions at the limit without evicting existing ones; expired Sessions count until cleanup.Jaws.MaxSessionsPerIPcap on all registered Sessions per client address bucket.SessionMiddlewarereturns HTTP 429 when that bucket is full and global capacity remains. Existing Sessions continue to work.SessionMiddlewarewhen the global cap or another creation failure prevents a required Session.NewSessionreturns nil without closing an existing cookie Session when admission or cookie publication fails.AutoSessionmay leave a Request without a Session at the cap; use the middleware where a Session is required.Both caps default to zero (disabled). Set the per-IP cap below the global cap to reserve capacity for other address buckets.
NewSessionneeds a free slot under each enabled cap to rotate a Session; a refused rotation retains the old Session. Visitors in one bucket share a quota, while clients using multiple addresses can still fill the global cap. Rate-limit Session-creating routes at the proxy.Verification
go generate ./...(no generated changes)go vet ./...,staticcheck ./...,golangci-lint run(viago run ...@v2.14.0),gosec -quiet ./...,go build ./...,gofumpt -lJAWS_REQUIRE_NODE=1 go test -race ./...andJAWS_REQUIRE_NODE=1 go test ./...deleteSessionIfCurrentLocked100% (99.7% package-wide)Benchmark
BenchmarkJawsMaintenanceSessionsmeasures sequential maintenance passes with 10,000 live Sessions. Apple M5 Max,-count=6 -benchtime=300ms -cpu=1, compared withbenchstat: