Cancel/stop replication triggers multipleResolves
- Dominant language
- JavaScript
- Stars
- 689
- Forks
- 167
- Avg merge
- 1h
- Merged PRs (30d)
- 1
Description
## Expected Behavior
I should be able to cancel replication without triggering multipleResolves. Or at least this is what I think because according with node.js docs this could be a bug or not.
> This is useful for tracking potential errors in an application while using the Promise constructor, as multiple resolutions are silently swallowed. However, the occurrence of this event does not necessarily indicate an error.
>
> -- https://nodejs.org/docs/latest/api/process.html#event-multipleresolves
## Current Behavior
Everytime I cancel a replication I trigger a couple of rejects.
## Possible Solution
Not sure because this might be more of an axios issue. But using an abort controller might be a solution.
## Steps to Reproduce (for bugs)
```javascript
'use strict';
require('dotenv').config();
const couchdb = require('nano')(process.env.COUCHDB);
process.on('multipleResolves', function multipleResolvesHandler (type, promise, reason) {
console.error('multiple resolve', { type, promise, reason });
setImmediate(() => process.exit(1));
});
let reader = couchdb.changesReader.start({
includeDocs: true
, batchSize: 25
, since: 0
});
reader.on('end', function () {
console.log('done');
});
couchdb.changesReader.stop(); // triggers an error
reader.once('batch', function onBatch (batch) {
console.log('got batch', !!batch);
couchdb.changesReader.stop();
});
```
## Context
I can not tell if I'm having an error I should care or not.
## Your Environment
* nano 10.1.3
* couchdb 3.1
* node 16.15.1 (linux)
Contributor guide
Research direction
Reproduce the issue with the provided Node.js script, focusing on changesReader.start and changesReader.stop during cancellation. Inspect how stopping replication handles the reader and rejected promises; done should be cancellation without triggering multipleResolves, or the expected error should be clearly documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100