fix: stop destroying connection pool after every sync request#270
fix: stop destroying connection pool after every sync request#270SoulPancake merged 5 commits intomainfrom
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 35 minutes and 5 seconds. ⌛ 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. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✨ Finishing Touches🧪 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project status has failed because the head coverage (69.85%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #270 +/- ##
==========================================
+ Coverage 69.84% 69.85% +0.01%
==========================================
Files 140 140
Lines 10743 10748 +5
==========================================
+ Hits 7503 7508 +5
Misses 3240 3240 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes an issue in the synchronous REST client where the connection pool was effectively being torn down after every request, preventing TCP/TLS connection reuse and hurting performance.
Changes:
- Stop clearing the sync client’s urllib3 pool manager at the end of every
request()call. - Minor request-building optimization: simplify JSON content-type detection (avoid regex) in both sync and async clients.
- Micro-optimizations: precompile ULID regex; avoid parsing URLs twice when deriving telemetry attributes.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
openfga_sdk/sync/rest.py |
Removes per-request pool teardown and simplifies JSON content-type detection. |
openfga_sdk/rest.py |
Matches sync behavior for JSON content-type detection (regex → lowercase substring check). |
openfga_sdk/validation.py |
Precompiles ULID regex at module scope to avoid recompiling per call. |
openfga_sdk/telemetry/attributes.py |
Parses URL once when extracting hostname/scheme telemetry attributes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Reference: regarding the auto release back to the pool https://urllib3.readthedocs.io/en/stable/advanced-usage.html#streaming-and-i-o |
Description
The sync REST client called self.close() at the end of every request() method (sync/rest.py, line 501). This invokes pool_manager.clear(), which per urllib3's implementation "empties the store of pools and directs them all to close" so every pooled TCP+TLS connection is destroyed after a single use. Each subsequent request had to establish a brand new connection from scratch.
The async client (openfga_sdk/rest.py) does not call self.close() after requests, so this bug was specific to the sync client path.
What problem is being solved?
How is it being solved?
What changes are made to solve it?
References
Review Checklist
main