feat: use @smithy/undici-http-handler for S3 client#1139
Conversation
0f9cf01 to
4f7c37c
Compare
Coverage Report for CI Build 27188171202Coverage decreased (-0.002%) to 76.43%Details
Uncovered Changes
Coverage Regressions2 previously-covered lines in 1 file lost coverage.
Coverage Stats💛 - Coveralls |
4f7c37c to
22defe5
Compare
There was a problem hiding this comment.
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
NodeHttpHandlerwithUndiciHttpHandleracross S3 and TUS code paths. - Introduce Undici-based
createAgentwith monitoring updates and agent shutdown now returning aPromise. - 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.
| let errorCount = 0 | ||
| dispatcher.on('connectionError', () => { | ||
| errorCount++ | ||
| }) |
There was a problem hiding this comment.
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.
| function updateHttpAgentMetrics(name: string, stats: AgentStats) { | ||
| const baseAttrs = { name, protocol: 'https' } |
| 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) |
| request.storage = new Storage(storageBackend, database, location) | ||
| request.cdnCache = new CdnCacheManager(request.storage) | ||
| }) |
| for (const origin of Object.keys(dispatcher.stats)) { | ||
| const s = dispatcher.stats[origin] as { | ||
| running: number | ||
| free?: number | ||
| pending: number | ||
| queued?: number | ||
| } |
| const httpAgent = createAgent('s3_worker', { | ||
| maxSockets: storageS3MaxSockets, | ||
| connectTimeoutMs: 5000, | ||
| requestTimeoutMs: storageS3ClientTimeout, | ||
| }) |
22defe5 to
d408f29
Compare
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.