Skip to content

Close the response before throwing RateLimitedException - #68

Merged
silvanocerza merged 2 commits into
ipinfo:masterfrom
nachomezzadra:fix/close-response-on-429
Nov 2, 2026
Merged

silvanocerza merged 2 commits into
ipinfo:masterfrom
nachomezzadra:fix/close-response-on-429

Conversation

@nachomezzadra

Copy link
Copy Markdown
Contributor

Fixes #67.

On a 429, handleRequest threw before closing the response, so the connection leaked and OkHttp logged a "connection was leaked" warning per request. This adds response.close() before the throw.

BaseRequestTest covers it with a fake 429 response served by an interceptor, so it needs no token or network. It checks the body's source was closed. A second test covers the 403 path, which already closed correctly, so it doesn't regress.

The existing tests that call the live API need IPINFO_TOKEN, which fork PRs don't get, so those may show red here. mvn test -Dtest=BaseRequestTest passes locally, and fails without the fix.

nachomezzadra and others added 2 commits October 30, 2026 11:10
A 429 threw before the response was closed, so the connection was never
returned to the pool and OkHttp logged a leak warning for every
rate-limited request.

Fixes ipinfo#67

@silvanocerza silvanocerza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 🙏

@silvanocerza

Copy link
Copy Markdown
Member

Tests are failing as expect since the IPINFO_TOKEN secret is not shared in PR from forks. Merging in any case.

@silvanocerza
silvanocerza merged commit 1a2b8ad into ipinfo:master Nov 2, 2026
0 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Response is never closed when the API returns 429, leaking connections

2 participants