apache / apache/pouchdb

Invalid attachment data on server error when getting doc with attachments

Open
#8,998 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
17.6k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

### Issue
When requesting a doc with attachments, if an attachment request fails, the doc attachment data will save the error message, instead of failing the request, resulting in invalid attachments.

This can happen during replication, bulkGet, etc.

### Info
- Environment: node.js, browser
- Adapter: http (?)
- Server: CouchDb

### Reproduce

Here's the gist: https://gist.github.com/dianabarsan/c08f5fc114c221a99d2afad7c870bf76

It adds a minimal nginx config that responds with a 400 to an attachment request, and proxies all other requests to a vanilla CouchDb 3.4.2, using docker compose.
Has a Javascript file that:
- creates a database
- creates a doc with a plain text attachment
- initializes a PouchDb connection and does a `db.get` and logs the content of the attachment, which is the default nginx html error page for 400.

Desired behavior here would be to throw an error when the attachment get request responds with an error.

Faulty code is here:
https://github.com/pouchdb/pouchdb/blob/master/packages/node_modules/pouchdb-core/src/adapter.js#L665 where the potential error is not handled.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.