Intermittent :timeout error in OAuth2(recv timeout set to 30s) => {:error, %OAuth2.Error{reason: :timeout}}

Hi Elixir community,

I’m encountering an intermittent {:error, %OAuth2.Error{reason: :timeout}} error while making OAuth2 API calls within Task.async processes. Even though I’ve set the recv timeout to 30 seconds, the error occasionally occurs before that time, seemingly for these asynchronous calls.And it rarely occurs to the non synchronous calls too.


  • OAuth2 library: I’m using the oauth2 library (~> 2.0).
  • Task context: The error appears for API calls made within Task.async blocks.
  • Regular interval: The timeout error seems to occur at roughly consistent intervals, despite the higher timeout setting.

Seeking help:

I’m hoping the community can help me identify the root cause of this intermittent timeout issue and suggest solutions for ensuring reliable OAuth2 authentication within my asynchronous tasks. Any insights on potential bottlenecks, library-specific settings, or alternative approaches to asynchronous API calls would be greatly appreciated.

I’m happy to provide further details or clarify any aspect of this issue as needed.

Thanks in advance for your assistance!


What API are you making Oauth2 calls to?

You mention you are using Task.async, how many tasks end up running at the same time?

Ebay API calls(eg: update_offer call and create_or_replace_inventory_item_group_call)

I will be running 20 tasks at the same time.