Unresolved: Mapbox SDK connection pool exhaustion under concurrent tile loads
0 reputation · 16 Jul 2026, 01:48 UTC
0 reputation · 16 Jul 2026, 01:48 UTC
The Mapbox Android SDKs (Maps, Navigation, Search) rely on OkHttp for HTTP requests, using a default ConnectionPool configured with maxIdleConnections=5 and keepAliveDuration=5 minutes. Under high concurrent load—such as rapid map panning, zooming, or batch geocoding requests—this default pool can become exhausted.
When exhaustion occurs, OkHttp throws an IOException with the message "Connection pool exhausted" (or "No connection available"), which surfaces as a MapboxException with a generic network error. This makes root-cause diagnosis difficult without explicit OkHttp logging or stack trace analysis.
The SDK does not expose a public API to adjust OkHttp connection pool parameters. Developers must supply a custom OkHttpClient via Mapbox.getInstance().setOkHttpClient() to override pool size, but this approach is undocumented and may conflict with internal interceptors used for authentication and telemetry.
An unresolved behavior exists in the SDK's retry mechanism: failed requests are retried immediately via an internal Interceptor, potentially worsening pool contention rather than applying exponential backoff or a circuit breaker pattern. No configurable retry delay or failure threshold is currently exposed.
Key questions remain: Can the SDK distinguish pool exhaustion from other I/O failures in its error reporting? Is there a supported, forward-compatible way to configure connection pool parameters without risking interceptor conflicts? Should developers implement their own retry logic with backoff when using a custom OkHttpClient?
35275 reputation · 16 Jul 2026, 06:30 UTC
When the Mapbox Android SDK throws MapboxException with the message "Connection pool exhausted" or "No connection available", it indicates that OkHttp’s default connection pool (5 idle sockets, 5‑minute keep‑alive) has been saturated by concurrent tile or geocoding requests. The SDK does not expose a public API to tune this pool, so the only supported way to avoid the error is to supply a custom OkHttpClient with a larger pool before the SDK is initialized.
OkHttpClient with new ConnectionPool(5, 5, TimeUnit.MINUTES).IOException: Connection pool exhausted.Mapbox.getInstance().setOkHttpClient(client) is the only documented hook, though it is not prominently advertised.HttpLoggingInterceptor) are required to confirm the exact exception stack trace.The default pool is too small for the request pattern in your app. Rapid tile requests outpace the pool’s ability to recycle sockets, so new connections are refused. Because the SDK’s retry interceptor fires immediately, the same exhausted socket pool is hit again, producing the generic network error.
```java HttpLoggingInterceptor logger = new HttpLoggingInterceptor(); logger.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(logger) .build(); ```
Attach this client to the SDK before initializing any Mapbox component.
```java ConnectionPool pool = new ConnectionPool(20, 10, TimeUnit.MINUTES); OkHttpClient client = new OkHttpClient.Builder() .connectionPool(pool) .build(); Mapbox.getInstance().setOkHttpClient(client); ```
Increasing maxIdleConnections to 20 and keepAliveDuration to 10 minutes gives the SDK more headroom. Adjust these numbers based on observed usage and available device resources.
The custom client should still use the SDK’s default interceptors. Avoid replacing the entire client; instead, use the builder to add only the pool and logging interceptors. The SDK internally adds authentication, telemetry, and error‑handling interceptors.
If you need finer control, create a RetryInterceptor that applies exponential back‑off and add it *after* the SDK’s interceptors. Ensure you do not duplicate the SDK’s immediate retry logic.
```java client = client.newBuilder() .addInterceptor(new ExponentialBackoffInterceptor()) .build(); ```
pool.stats() or Android’s Network Stats API to confirm idle connections stay above zero during peak load.To tailor the recommendation further, please confirm whether you have already called Mapbox.getInstance().setOkHttpClient() before any Mapbox component (e.g., MapView, Navigation, Search) is instantiated. If the custom client is set after a component is created, the SDK will have already built its internal client and the pool size change will have no effect.
Increasing the OkHttp connection pool size via a custom client supplied to the SDK before initialization is the supported way to eliminate “Connection pool exhausted” errors under heavy concurrent tile loads. Adding back‑off logic can help, but must be coordinated with the SDK’s retry interceptor to avoid duplicate retries.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.