Skip to content

Fix: surface HTTP 413 and other 4xx errors via replication error event (issue #9165)#9236

Closed
TeapoyY wants to merge 1 commit intoapache:masterfrom
TeapoyY:fix/pouchdb-9135-http-413-replication
Closed

Fix: surface HTTP 413 and other 4xx errors via replication error event (issue #9165)#9236
TeapoyY wants to merge 1 commit intoapache:masterfrom
TeapoyY:fix/pouchdb-9135-http-413-replication

Conversation

@TeapoyY
Copy link
Copy Markdown

@TeapoyY TeapoyY commented Apr 19, 2026

Summary

Fixes #9165 — HTTP 413 during live replication is not surfaced via replication events.

Problem

When using PouchDB live replication with CouchDB, a \413 Content Too Large\ response from _bulk_docs\ is visible in DevTools but not exposed through any replication event. The \paused(err)\ event receives \err === undefined.

Root Cause

In \completeReplication(), only 'unauthorized'\ (401) and 'forbidden'\ (403) errors are emitted via the 'error'\ event. All other errors (including HTTP 413 Payload Too Large from _bulk_docs) fall through to the backoff/retry path, causing infinite retries without surfacing the error.

Fix

Treat 4xx client errors (except 401/403 already handled) the same as auth errors — emit them via the 'error'\ event and stop retrying. This is correct because 4xx errors indicate a problem with the request itself (e.g., content too large, bad request) that retrying cannot fix.

The fix is in \packages/node_modules/pouchdb-replication/src/replicate.js:

\\javascript
} else if (fatalError.status >= 400 && fatalError.status < 500) {
// Surface 4xx client errors (e.g. 413 Content Too Large from _bulk_docs)
// via the error event instead of retrying, since retrying won't fix them.
returnValue.emit('error', fatalError);
returnValue.removeAllListeners();
}
\\

Behavior Change

  • Before: 413 errors during \�ulkDocs\ would silently retry forever; \paused(err)\ got \undefined\
  • After: 413 (and other 4xx) errors are emitted via the 'error'\ event, so
    eplication.on('error', err => ...)\ receives the actual error with status/details

Issue apache#9165: HTTP 413 during live replication is not surfaced via replication events.

Root cause: In completeReplication(), only 'unauthorized' (401) and
'forbidden' (403) errors are emitted via the 'error' event. All other
errors (including HTTP 413 Payload Too Large from _bulk_docs) fall
through to the backoff/retry path.

Fix: Treat 4xx client errors (except 401/403 already handled) the same
as auth errors - emit them via the 'error' event and stop retrying.
This is correct because 4xx errors indicate a problem with the request
itself (e.g., content too large, bad request) that retrying cannot fix.
The error is now properly surfaced to users via the 'error' event on
the replication object.
@janl
Copy link
Copy Markdown
Member

janl commented Apr 19, 2026

Thanks for the contribution. Can you please use our pull request template?

@TeapoyY
Copy link
Copy Markdown
Author

TeapoyY commented Apr 20, 2026

Closing - not a bounty issue

@TeapoyY TeapoyY closed this Apr 20, 2026
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.

HTTP 413 during live replication is not surfaced via replication events

2 participants