Skip to content

Calling enqueue() from OkHttp’s Dispatcher shouldn’t count against thread limits #7904

@swankjesse

Description

@swankjesse

With coroutines it’s pretty common to use Call.enqueue() in the implementation of an Authenticator or Interceptor.

This ends badly because if the Dispatcher’s is at its configured limit there’s no thread to serve the enqueued call, and the overall network stack can deadlock!

We’ve documented this a bit, but it’s still a hazard. Especially when features like suspend on Wire gRPC and Retrofit make it very easy to use a background thread without even knowing it.

Rather than broadly warning everyone of the dangers of this antipattern, we should just make it so enqueued calls made on OkHttp’s Dispatcher thread don’t count against dispatcher limits. Those calls should be performed immediately. This will avoid deadlocks and remove a footgun from our API.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions