Hi, We are using Airbyte - Cloud Version. we’re se...
# replication-troubleshooting
a
Hi, We are using Airbyte - Cloud Version. we’re seeing intermittent 401 Unauthorized mid-sync (usually after a few pages) across multiple declarative HTTP sources. A full rerun later succeeds with no config changes. One source uses Bearer API key , another uses Basic; both have concurrency=1 with offset pagination. Any guidance on what could be the root cause for these kind of errors and the best possible solution to mitigate these kind of failures?
k
Intermittent 401s mid-sync are a known class of issues in Airbyte HTTP sources and can stem from a few root causes: Likely causes - Token expiry or race conditions during retries/backoff: Requests are prepared once, including auth headers, then retried without rebuilding headers. If a retry crosses the token’s expiry boundary, the server returns 401. This is especially visible with OAuth/session tokens but can also manifest with Bearer tokens if upstream rotates/invalidates tokens. [[auth token race](https://github.com/airbytehq/airbyte/issues/31687)] - Backend intermittency: Some APIs sporadically return 401 during long runs or polling, and a simple retry resolves it. [[Amazon Ads 401 retry](https://github.com/airbytehq/airbyte/issues/54650); [Custom connector 401s fixed by retries](https://github.com/airbytehq/airbyte/issues/48740)] - Connector logic not refreshing/propagating new auth in all code paths (e.g., child/association requests), causing mid-sync failures even when main flow refreshes. [[HubSpot associations 401 mid-sync](https://github.com/airbytehq/airbyte/issues/62467)] Mitigations you can apply to declarative HTTP sources - Add explicit 401 retry handling with backoff in the stream(s). Several users resolved intermittent 401s by enabling error handling and backoff for 401, allowing transient auth hiccups to clear. [[Custom connector fix via 401 retry](https://github.com/airbytehq/airbyte/issues/48740); [Amazon Ads needs 401 retry](https://github.com/airbytehq/airbyte/issues/54650)] - If using OAuth/session-like auth in any part of the flow, ensure the authenticator can refresh and that a new Authorization header is applied on retries. Airbyte community threads show adding token refresh in should_retry/backoff paths for 401, then forcing the request to be retried with updated headers. [[Forum 401 handling example](https://discuss.airbyte.io/t/1227); [Kyriba example refresh-on-401](https://discuss.airbyte.io/t/2231/)] - Proactively refresh before expiration (add a buffer). The CDK doesn’t pad token expiry, so calls just before expiry can arrive after expiration and fail with 401. If you control the token provider, refresh when “close to” expiry. [[auth token race](https://github.com/airbytehq/airbyte/issues/31687)] - For APIs behind CDNs/security layers, expect occasional spurious 4xx; robust retry/backoff is recommended. [[HubSpot mid-sync behavior](https://github.com/airbytehq/airbyte/issues/62467)] Notes for your specific auth types - Bearer API key/Basic: These don’t “expire” client-side, but upstreams can intermittently return 401 (temporary auth checks, edge cache, or backend blips). Applying limited retries with jittered backoff on 401 often stabilizes long syncs. [[Custom connector fix via 401 retry](https://github.com/airbytehq/airbyte/issues/48740); [Amazon Ads 401 transient](https://github.com/airbytehq/airbyte/issues/54650)] - If any source is actually OAuth under the hood (or session token), ensure refresh logic runs in all paths and that retries rebuild headers. [[auth token race](https://github.com/airbytehq/airbyte/issues/31687); [HubSpot associations path](https://github.com/airbytehq/airbyte/issues/62467)] Recommended next steps - Enable error handling: retry 401 with exponential backoff (and small max tries) in each affected stream. - If using OAuth/session: on 401, refresh the token and ensure the Authorization header is replaced before the retry. [[Forum 401 handling example](https://discuss.airbyte.io/t/1227); [Kyriba example](https://discuss.airbyte.io/t/2231/)] - Add a token-expiry buffer if applicable. [[auth token race](https://github.com/airbytehq/airbyte/issues/31687)] - Keep concurrency=1 for now (as you have) to reduce timing races; if you later increase it, ensure all concurrent paths share refreshed credentials correctly. [[HubSpot associations note](https://github.com/airbytehq/airbyte/issues/62467)] If you need concrete snippets for a Python CDK connector (e.g., should_retry/backoff on 401 and header refresh), let me know which connector type you’re using (declarative vs Python) and I can point to the relevant examples. [[Forum 401 handling example](https://discuss.airbyte.io/t/1227); [Kyriba example](https://discuss.airbyte.io/t/2231/)]