Repository navigation
Allow stateful HTTP endpoints to recover after DELETE - #307
EhsanAzish80 wants to merge 7 commits into
Conversation
varun06
left a comment
There was a problem hiding this comment.
Thanks @EhsanAzish80, the Server.stop() change is a real fix. Reverting just that part makes the slow-session test fail. I ran the new tests many times locally with no flakes, and the suite passes.
Two things before merging, since this becomes the recommended production API:
- Validate before creating the session. The validation pipeline (Origin, bearer auth, Accept/Content-Type) only runs inside
transport.handleRequest, afterserverFactoryandserver.start. With aBearerTokenValidator, aninitializewithout a token correctly gets a 401, but aServerhas already been built and started (factory called once). Could the manager runvalidationPipeline.validate(...)on the initialize request before calling the factory? - Limit the number of sessions. Each initialize creates a
Serverthat lives up tosessionTimeout
(1h by default). AmaxSessionsoption that rejects new sessions with 503 would avoid unbounded growth.
Smaller, non-blocking:
lastAccessedAtonly updates on incoming requests, so a client holding a GET stream open without
POSTs gets stopped mid-stream after the timeout.removeExpiredSessions()awaitsserver.stop()inside the request path; the 60s cleanup task already
covers it.- The 500 body includes the factory's
localizedDescription; a generic message plus a log entry would be safer. - Worth a release note that
Server.stop()now cancels in-flight handlers for all transports. - Tests for expiry, a failed DELETE, and a throwing factory would round this out.
9eae4c8 to
ec9d423
Compare
|
Updated this for the two review points: initialize now runs validation before the server factory, and |
|
Thanks @EhsanAzish80, both points are addressed. One thing left: Also worth deciding on the default Smaller, non-blocking: the manager repeats the transport's default validator list (a shared static default |
|
Thanks Varun, I updated #307 in The 5 focused session manager tests and all 566 Swift tests passed locally. The new session tests also passed in Ubuntu CI, and macOS, conformance, docs, and Linux static build are green. The Ubuntu test job hit 60-second limits in AI helped write the new tests; I ran them. |
|
Thanks @EhsanAzish80. I checked the latest changes against Varun's comments and his main points are covered: validation now runs once before the server factory, A few things I noticed, in case they're useful:
|
|
Thanks, I addressed these in |
Fixes #286 for stateful HTTP endpoints. The session manager creates a fresh server and transport for each initialize. DELETE stops the old server and lets the client initialize a new session. A rejected DELETE leaves the existing session available; the manager removes it only after DELETE succeeds.
Initialize is validated once before the server factory runs.
maxSessionsis opt-in, and a configured limit returns 503 when active or in-progress sessions reach it. Factory errors are logged without exposing their details in the HTTP response.Open GET streams keep their sessions from expiring. Expired sessions stop in a background task so the next request does not wait for cleanup.
Server.stop()also cancels in-flight handlers for every transport.The Swift 6.1 CI job is pinned to Ubuntu 24.04, and existing client tests wait for initialize instead of a fixed 10 ms sleep. These CI fixes are shared with #295 and #298.
Tests: 53 focused HTTP transport tests and all 589 Swift tests passed locally on
c73ab13. The new expiry test passed five additional runs. All six CI jobs passed on the same commit, including Ubuntu, both macOS jobs, conformance, documentation, and the Linux static build. AI helped write the tests; I ran them.