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

no error event on createChannel since V10.0.0 #726

Closed
SSANSH opened this issue Jun 19, 2023 · 1 comment
Closed

no error event on createChannel since V10.0.0 #726

SSANSH opened this issue Jun 19, 2023 · 1 comment

Comments

@SSANSH
Copy link

SSANSH commented Jun 19, 2023

Since the version V10.0.0 and the update of the code "Use Native promises (#689, thank you @mohd-akram and @kibertoad)"

// Do the remarkably simple channel open handshake async open() { const ch = await this.allocate.bind(this)(); return ch.rpc(defs.ChannelOpen, {outOfBand: ""}, defs.ChannelOpenOk); }

When I create channel like this currentChannel = await conn.createChannel();

and listen for event close

The error event is never emit in case "No channels left to allocate" using :

currentChannel.on('error', (error) => { ....

You can reproduce by comment line if (next < 0 || next > this.channelMax) into amqplib/lib/connection.js, calling createChannel and listen for error event.

Thanks.

@SSANSH SSANSH closed this as completed Jun 19, 2023
@cressie176
Copy link
Collaborator

Hi @SSANSH,

Something odd here. It does not make sense that createChannel would return a channel object with an event handler, if the channel could not be allocated. It also makes no sense that an error event would be emitted on a previously created and working channel, if a call to create a new channel failed.

The following code behaves as I would expect, and the same for me with amqplib v0.9.1 and v0.10.3 using node 18...

const amqplib = require('amqplib');

(async () => {
  const connection = await amqplib.connect('amqp://localhost:5672?channelMax=1');
  connection.on('error', (error) => {
    console.log('Connection Error', { error });
  })

  await createChannel();
  await createChannel();

  async function createChannel()  {
    try {
      const channel = await connection.createChannel();
      channel.on('close', (error) => {
        console.log('Channel Close Event', { error });
      });
      channel.on('error', (error) => {
        console.log('Channel Error Event', { error });
      })
      console.log('Channel Created OK')
    } catch (error) {
      console.log('Caught Error', { error });
    }
  }

})();
Channel Created OK
Caught Error {
  error: Error: No channels left to allocate
      at C.freshChannel (/Users/steve/Development/amqp-node/amqplib-726/node_modules/amqplib/lib/connection.js:459:11)
      at C.allocate (/Users/steve/Development/amqp-node/amqplib-726/node_modules/amqplib/lib/channel.js:52:29)
      at tryCatcher (/Users/steve/Development/amqp-node/amqplib-726/node_modules/bluebird/js/release/util.js:16:23)
      at Promise.attempt.Promise.try (/Users/steve/Development/amqp-node/amqplib-726/node_modules/bluebird/js/release/method.js:39:29)
      at Channel.open (/Users/steve/Development/amqp-node/amqplib-726/node_modules/amqplib/lib/channel_model.js:65:23)
      at ChannelModel.createChannel (/Users/steve/Development/amqp-node/amqplib-726/node_modules/amqplib/lib/channel_model.js:31:19)
      at createChannel (/Users/steve/Development/amqp-node/amqplib-726/index.js:15:38)
      at /Users/steve/Development/amqp-node/amqplib-726/index.js:11:9
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants