Skip to content

Commit

Permalink
fix(cluster): passing frozen natMap option causes crash
Browse files Browse the repository at this point in the history
Closes: #887
  • Loading branch information
luin committed Jun 11, 2019
1 parent 1d606e4 commit 3bc6165
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cluster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ class Cluster extends EventEmitter {
const mapped = this.options.natMap[key]
if (mapped) {
debug('NAT mapping %s -> %O', key, mapped)
return mapped
return Object.assign({}, mapped)
}
}
return typeof nodeKey === 'string' ? nodeKeyToRedisOptions(nodeKey) : nodeKey
Expand Down
27 changes: 27 additions & 0 deletions test/functional/cluster/nat.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,31 @@ describe('NAT', () => {

cluster.get('foo')
})

it('keeps options immutable', (done) => {
const slotTable = [
[0, 16383, ['192.168.1.1', 30001]]
]

new MockServer(30001, null, slotTable)

const cluster = new Redis.Cluster([{
host: '127.0.0.1',
port: 30001
}], Object.freeze({
natMap: Object.freeze({
'192.168.1.1:30001': Object.freeze({host: '127.0.0.1', port: 30001})
})
}))

const reset = spy(cluster.connectionPool, 'reset')

cluster.on('ready', () => {
expect(reset.secondCall.args[0]).to.deep.equal([
{host: '127.0.0.1', port: 30001, readOnly: false}
])
cluster.disconnect()
done()
})
})
})

0 comments on commit 3bc6165

Please sign in to comment.