Skip to content

Commit ab0db59

Browse files
committed
Raise AMQPError when channelMax is reached
Rather then letting the server close the whole connection with a connection error. Fixes #43
1 parent b279e86 commit ab0db59

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/amqp-base-client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ export abstract class AMQPBaseClient {
6666
if (!id)
6767
id = this.channels.findIndex((ch) => ch === undefined)
6868
if (id === -1) id = this.channels.length
69-
// FIXME: check max channels (or let the server deal with that?)
69+
if (id > this.channelMax) return Promise.reject(new AMQPError("Max number of channels reached", this))
70+
7071
const channel = new AMQPChannel(this, id)
7172
this.channels[id] = channel
7273

test/test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,3 +664,17 @@ test("can republish in consume block without race condition", async t => {
664664
await t.notThrowsAsync(() => conn.close())
665665
console.log(conn.bufferPool.length)
666666
})
667+
668+
test("raises when channelMax is reached", async t => {
669+
const amqp = new AMQPClient("amqp://127.0.0.1")
670+
const conn = await amqp.connect()
671+
for (let i = 0; i < conn.channelMax; i++) {
672+
await conn.channel()
673+
}
674+
const error = await t.throwsAsync(conn.channel())
675+
t.is(error.message, 'Max number of channels reached');
676+
677+
// make sure other channels still work
678+
const ch1 = await conn.channel(1)
679+
await t.notThrowsAsync(ch1.basicQos(10))
680+
})

0 commit comments

Comments
 (0)