Added shared keep-alive agent to external HTTP requests#28228
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
WalkthroughThis PR improves image probing reliability and connection efficiency by introducing three coordinated changes: (1) adding shared keep-alive HTTP/HTTPS agents to the external request client so outbound connections are pooled and reused, (2) creating a local probe helper that uses the pooled client instead of 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Introduces a shared keep-alive HTTP/HTTPS agent pool for outbound got requests in request-external.js to stop one-socket-per-request churn (which was saturating the NAT gateway's connection-rate limit). Image probing in probe-image-size is rewired through the same got instance so the parallel meta/image-dimensions fetches reuse the pool and pick up the existing SSRF protections; the outer "probe unresponsive" timeout now destroys the underlying stream so the pooled socket isn't leaked.
Changes:
- Add shared
http.Agent/https.Agent(keep-alive,keepAliveMsecs: 60000,maxSockets/maxFreeSockets: 256) and wire them into the centralgotinstance viagotOpts.agent. - Replace direct use of
probe-image-sizeinimage-utils.jswith a wrapper that streams the body throughexternalRequest.stream, exposing.streamon the returned promise. - Update
_probeImageSizeFromUrlto destroy the probe stream when the outer timeout wins, and clear the timeout in afinallyto avoid leaks.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| ghost/core/core/server/lib/request-external.js | Adds shared keep-alive agents and registers them in the got.extend options. |
| ghost/core/core/server/lib/image/image-utils.js | Wraps probe-image-size over externalRequest.stream, exposing the underlying stream for cancellation. |
| ghost/core/core/server/lib/image/image-size.js | Reworks the probe/timeout race to destroy the stream on timeout and clear the timer on settle. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ref https://linear.app/ghost/issue/BER-3690 - got.extend in request-external.js had no agent configured, so every oEmbed / webmention / recommendation / image probe opened a fresh socket - on a NAT-gatewayed VPC this holds the gateway at its connection-rate ceiling and causes port-collision drops that gateway sizing won't fix - adds a shared http/https Agent (keepAlive: true, keepAliveMsecs: 60s, maxSockets: 256) wired into the central got instance - routes probe-image-size through externalRequest.stream so the parallel cover/author/og/twitter/logo fetches from meta/image-dimensions.js reuse the same pool (and pick up the existing SSRF protections)
af82bc6 to
2b6ec92
Compare
|
Actionable comments posted: 0 |
ref https://linear.app/ghost/issue/BER-3690