Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pipeline with transactions causes unhandled warnings #884

Merged
merged 3 commits into from
Jun 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export function addTransactionSupport (redis) {
if (this._transactions > 0) {
exec.call(pipeline)
}

// Returns directly when the pipeline
// has been called multiple times (retries).
if (this.nodeifiedPromise) {
return exec.call(pipeline)
}
const promise = exec.call(pipeline)
return asCallback(promise.then(function (result) {
const execResult = result[result.length - 1]
Expand Down
42 changes: 42 additions & 0 deletions test/functional/cluster/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('cluster:transaction', function () {
var cluster = new Redis.Cluster([
{ host: '127.0.0.1', port: '30001' }
]);

cluster.multi().get('foo').set('foo', 'bar').exec(function (err, result) {
expect(err).to.eql(null);
expect(result[0]).to.eql([null, 'bar']);
Expand Down Expand Up @@ -97,4 +98,45 @@ describe('cluster:transaction', function () {
done();
});
});

it('should not print unhandled warnings', function (done) {
const errorMessage = 'Connection is closed.'
var slotTable = [
[0, 16383, ['127.0.0.1', 30001]]
];
new MockServer(30001, function (argv) {
if (argv[0] === 'exec' || argv[1] === 'foo') {
return new Error(errorMessage)
}
}, slotTable);

var cluster = new Redis.Cluster([
{ host: '127.0.0.1', port: '30001' }
], {
maxRedirections: 3
});

let isDoneCalled = false
const wrapDone = function (error) {
if (isDoneCalled) {
return
}
isDoneCalled = true
process.removeAllListeners('unhandledRejection')
done(error)
}

process.on('unhandledRejection', err => {
wrapDone(new Error('got unhandledRejection: ' + err.message))
})
cluster.multi().get('foo').set('foo', 'bar').exec(function (err) {
expect(err).to.have.property('message', errorMessage)
cluster.on('end', function () {
// Wait for the end event to ensure the transaction
// promise has been resolved.
wrapDone();
})
cluster.disconnect();
});
});
});