Fix request timeouts under concurrent load#12
Conversation
WalkthroughThis PR increases the server write timeout, changes response error logging in the Telegram handler, optimizes image size retrieval by using HTTP HEAD (removing temp file I/O), and removes an unused tmpPath constant. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/feed/extract.go (1)
329-349:⚠️ Potential issue | 🟡 MinorGood optimization switching to HEAD requests. One gap: the response status code is not checked before trusting
ContentLength.A non-2xx response (e.g., 403, 404, 500) could still carry a
Content-Lengthheader representing an error page body, not the image. Consider adding a status check:Proposed fix
defer res.Body.Close() - if res.ContentLength > 0 { + if res.StatusCode >= 200 && res.StatusCode < 300 && res.ContentLength > 0 { return res.ContentLength }
🧹 Nitpick comments (1)
internal/api/rest/server.go (1)
48-48: Consider whether 300s WriteTimeout is appropriate for your deployment.A 5-minute write timeout means each connection can be held open for that duration. While the comment explains the rationale (semaphore wait + scraping), this significantly increases the server's exposure to slow-client resource exhaustion. If you're behind a reverse proxy (e.g., nginx, Cloudflare), ensure it enforces its own tighter upstream timeout so that stalled connections don't accumulate at the Go server level.
If only a subset of endpoints require long processing, a per-request
http.TimeoutHandlerwrapper on those routes would let you keep a shorter globalWriteTimeout.
Summary by CodeRabbit
Performance Improvements
Bug Fixes
Chores