Skip to content

Do not re-schedule request head timeout for HTTP/2 and HTTP/3 - #108

Merged
aryan-25 merged 1 commit into
swift-server:mainfrom
aryan-25:optimise-read-timeout
Aug 4, 2026
Merged

Do not re-schedule request head timeout for HTTP/2 and HTTP/3#108
aryan-25 merged 1 commit into
swift-server:mainfrom
aryan-25:optimise-read-timeout

Conversation

@aryan-25

@aryan-25 aryan-25 commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Currently, in RequestTimeoutHandler, we reschedule the request timeout after seeing the request end part so that the timeout is ready for the next request on the channel:

// Re-arm the header timer so the next request on this connection is also protected.
if let readHeaderTimeout {
self.scheduleTimeout(readHeaderTimeout, context: context)
}

However, this is only really necessary for HTTP/1. For HTTP/2 and HTTP/3, there can only ever be one request on a stream channel, so we do not need to reschedule the header timeout.

Avoiding this re-scheduling also means we can avoid the cost of cancelling the re-scheduled task (which is not required in the first place) when the handler is imminently removed after the request has finished.

Modifications

Introduced a new boolean flag named expectMultipleRequests to RequestTimeoutHandler. When expectMultipleRequests == false, the header timeout is not rescheduled after receiving a request end part.

Result

Unnecessary creation and cancellation of tasks avoided.

@aryan-25
aryan-25 requested a review from gjcairo August 3, 2026 17:24
@aryan-25 aryan-25 added the 🔨 semver/patch No public API change. label Aug 3, 2026
@aryan-25
aryan-25 merged commit 2535484 into swift-server:main Aug 4, 2026
18 of 23 checks passed
@aryan-25
aryan-25 deleted the optimise-read-timeout branch August 4, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants