apache / couchdb-nano

Nano: The official Apache CouchDB library for Node.js
https://www.npmjs.com/package/nano
Apache License 2.0
653 stars 165 forks source link

Cancel/stop replication triggers multipleResolves #341

Open revington opened 9 months ago

revington commented 9 months ago

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)


'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