Add a semaphore to limit concurrent t.me access#11
Conversation
|
Warning Rate limit exceeded@nDmitry has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 17 minutes and 43 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughThe scraper now enforces concurrent request limits using a semaphore mechanism capped at 3 simultaneous requests. A new semaphore type with acquire and release methods was introduced, integrated into the Scraper struct, and initialized during instantiation to control HTTP visit concurrency. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
internal/feed/scraper.go (1)
23-37: Consider adding context support toacquireto prevent goroutine leaks.The current
acquire()blocks unconditionally. If a caller's context is cancelled while waiting for the semaphore, the goroutine will block forever, potentially causing leaks under cancellation scenarios.♻️ Suggested context-aware acquire
-func (s *semaphore) acquire() { - s.c <- struct{}{} +func (s *semaphore) acquire(ctx context.Context) error { + select { + case s.c <- struct{}{}: + return nil + case <-ctx.Done(): + return ctx.Err() + } }Then update the call site in
Scrape:- s.sema.acquire() - defer s.sema.release() - - if err := c.Visit(channel.URL); err != nil { + if err := s.sema.acquire(ctx); err != nil { + return nil, fmt.Errorf("could not acquire semaphore: %w", err) + } + defer s.sema.release() + + if err := c.Visit(channel.URL); err != nil {
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
internal/feed/scraper.go
🔇 Additional comments (3)
internal/feed/scraper.go (3)
21-22: LGTM!Reasonable concurrency limit constant.
39-51: LGTM!Clean integration of the semaphore into the
Scraperstruct with proper initialization.
95-100: Good use ofdeferfor release.The placement correctly limits concurrent
Visitcalls, anddeferensures the semaphore is released on all exit paths including errors.
bd43b84 to
d7996ed
Compare
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.