Skip to content

feat: use @smithy/undici-http-handler for S3 client#1139

Open
mcollina wants to merge 1 commit into
supabase:masterfrom
mcollina:mcollina/undici-http-handler
Open

feat: use @smithy/undici-http-handler for S3 client#1139
mcollina wants to merge 1 commit into
supabase:masterfrom
mcollina:mcollina/undici-http-handler

Conversation

@mcollina

@mcollina mcollina commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Switches the S3 client request handler from @smithy/node-http-handler (agentkeepalive) to @smithy/undici-http-handler (undici Dispatcher). Pool metrics rewired onto undici stats.

@mcollina mcollina force-pushed the mcollina/undici-http-handler branch from 0f9cf01 to 4f7c37c Compare June 8, 2026 10:35
@coveralls

coveralls commented Jun 8, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 27188171202

Coverage decreased (-0.002%) to 76.43%

Details

  • Coverage decreased (-0.002%) from the base build.
  • Patch coverage: 6 uncovered changes across 2 files (17 of 23 lines covered, 73.91%).
  • 2 coverage regressions across 1 file.

Uncovered Changes

File Changed Covered %
src/internal/http/agent.ts 19 14 73.68%
src/storage/backend/s3/adapter.ts 2 1 50.0%
Total (4 files) 23 17 73.91%

Coverage Regressions

2 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
src/storage/protocols/tus/s3-locker.ts 2 78.37%

Coverage Stats

Coverage Status
Relevant Lines: 11024
Covered Lines: 8855
Line Coverage: 80.32%
Relevant Branches: 6464
Covered Branches: 4511
Branch Coverage: 69.79%
Branches in Coverage %: Yes
Coverage Strength: 367.1 hits per line

💛 - Coveralls

@mcollina mcollina force-pushed the mcollina/undici-http-handler branch from 4f7c37c to 22defe5 Compare June 8, 2026 12:46
@mcollina mcollina marked this pull request as ready for review June 8, 2026 15:00
@mcollina mcollina requested a review from a team as a code owner June 8, 2026 15:00
Copilot AI review requested due to automatic review settings June 8, 2026 15:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR migrates the S3 HTTP stack from @smithy/node-http-handler + agentkeepalive to Undici (@smithy/undici-http-handler + undici Agent), adds request/connect timeouts to the shared agent, and updates lifecycle handling accordingly.

Changes:

  • Replace Smithy NodeHttpHandler with UndiciHttpHandler across S3 and TUS code paths.
  • Introduce Undici-based createAgent with monitoring updates and agent shutdown now returning a Promise.
  • Add configurable S3 client request timeout wiring via config (storageS3ClientTimeout).

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/storage/renderer/renderer.ts Updates abort-handling comment to reflect Undici-based Smithy handler.
src/storage/events/base-event.ts Passes connect/request timeouts into the HTTP agent used by background S3 worker flows.
src/storage/backend/s3/adapter.ts Switches S3 backend to UndiciHttpHandler, updates monitoring, and makes close() return a promise.
src/storage/backend/adapter.ts Broadens close() to allow async cleanup (Promise<void>).
src/internal/http/agent.ts Replaces agentkeepalive with Undici Agent, and rewrites metrics collection/close semantics.
src/http/routes/tus/index.ts Migrates TUS S3 usage to UndiciHttpHandler and awaits agent close on shutdown.
src/http/plugins/storage.ts Removes the Fastify onClose hook that previously closed the storage backend.
package.json Removes @smithy/node-http-handler and agentkeepalive, adds @smithy/undici-http-handler and @smithy/types.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +50 to +53
let errorCount = 0
dispatcher.on('connectionError', () => {
errorCount++
})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a regression — agentkeepalive's errorSocketCount / timeoutSocketCount / createSocketErrorCount were also cumulative counters that only ever increased. Same semantics as before. Switching to a true counter metric is a separate cleanup unrelated to this migration.

Comment on lines +76 to +77
function updateHttpAgentMetrics(name: string, stats: AgentStats) {
const baseAttrs = { name, protocol: 'https' }
Comment on lines +82 to 89
httpPoolErrors.record(stats.errorSocketCount, { ...baseAttrs, type: 'connect_error' })
}

export function watchAgent(name: string, protocol: 'http' | 'https', agent: Agent | HttpsAgent) {
export function watchAgent(name: string, dispatcher: Agent, getErrorCount: () => number) {
return setInterval(() => {
const httpStatus = agent.getCurrentStatus()

const httpStats = gatherHttpAgentStats(httpStatus)

updateHttpAgentMetrics(name, protocol, httpStats)
const stats = gatherDispatcherStats(dispatcher, getErrorCount())
updateHttpAgentMetrics(name, stats)
}, 5000)
Comment on lines 38 to 40
request.storage = new Storage(storageBackend, database, location)
request.cdnCache = new CdnCacheManager(request.storage)
})
Comment on lines +97 to 103
for (const origin of Object.keys(dispatcher.stats)) {
const s = dispatcher.stats[origin] as {
running: number
free?: number
pending: number
queued?: number
}
Comment on lines 97 to 101
const httpAgent = createAgent('s3_worker', {
maxSockets: storageS3MaxSockets,
connectTimeoutMs: 5000,
requestTimeoutMs: storageS3ClientTimeout,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants