Skip to content

Close the response before throwing RateLimitedException - #68

Open
nachomezzadra wants to merge 1 commit into
ipinfo:masterfrom
nachomezzadra:fix/close-response-on-429
Open

nachomezzadra wants to merge 1 commit into
ipinfo:masterfrom
nachomezzadra:fix/close-response-on-429

Conversation

@nachomezzadra

Copy link
Copy Markdown

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.

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

This branch has not been deployed

No deployments
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

1 participant