-
Notifications
You must be signed in to change notification settings - Fork 476
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
Potentially unhandled rejection [1] Error: Channel ended, no reply will be forthcoming #250
Comments
In a different script I'm receiving the same error. I take the following steps:
This time there is no race condition, the error just happens when I attempt to close the channel. |
You can synchronise on the promise returned from |
@cboden Did you find any solution? I'm seeing the same error in 0.5.1 when doing the following:
|
Just in case someone is still struggling, I have the code below working fine:
|
@waubau I used await for |
Bumping. Same error as @OhEn |
I was facing this error as well. Turns out, I simply wasn't using - channel.assertQueue(q, { durable: true, exclusive: false });
+ await channel.assertQueue(q, { durable: true, exclusive: false }); |
The same worked for me. |
We're seeing this issue even now, 4 years after initial report.
I've gone over our code numerous times to ensure everything is being |
I used a dirty workaround to fix this: function waitForPending(channel) {
const intervalTime = 100;
let timeout = 5000;
return new Promise(resolve => {
if (channel.pending.length === 0 && channel.reply === null) {
resolve();
} else {
const interval = setInterval(() => {
if (channel.pending.length === 0 && channel.reply === null) {
// everything is clean
clearInterval(interval);
resolve();
}
timeout -= intervalTime;
if (timeout <= 0) {
// timed out, but you probably still want to close it, so resolve()
clearInterval(interval);
resolve();
}
}, intervalTime);
}
})
} Also note that after await waitForPending(channel);
await channel.close();
await waitForPending(channel);
await connection.close(); This is not bulletproof, I guess, and using setInterval is dumb, but I have not found any events I can listen to monitor |
Seeing the same problem just because a channel.close() after publishing to a queue... |
I had the same issue. |
Whenever I see similar "no reply will be forthcoming" errors it's always ends up being a concurrency issue with my own code. Typically what happens is that I am asynchronously acknowledging messages, then something closes the channel - either because of an error or through deliberate action on my part. Any attempts to use the channel after this happens by one of the other asynchronous pieces of work can result in this error. The solution is to be very careful about how you control the use of shared channels. |
Thank you very much - adding a timeout before closing a connection also helped me to solve this error on NestJS in Jest tests after I added RabbitMQ dependencies/functionality. |
I had the same issue. Hope following code will help you. PUBLISHER
SUBSCRIBER
|
Adding an arbitrary timeout is fine if you're writing a throw away script, but I wouldn't want to take this approach for a proper application. A better solution is to ensure you
If you do this you should not receive the "Channel ended, no reply will be forthcoming" error |
Kindly, does anyone have an idea how I might fix this error (and proceed with my work) in NestJS? I've been unable to do anything and it blocks me. I've tried all the examples above and to no avail. Please, help.🤲🏼 Cc: @cressie176 |
I'm not familiar with NestJS / Nest's RabbitMQ integration. However, in general if you're getting a channel error, it's usually because you've tried to do something the broker didn't like, e.g. recreate a queue / exchange with different configuration. Another frequent cause is that you've tried to use a channel after it has been closed. Yet another is that you have sent a command to RabbitMQ and are awaiting a reply, but the channel closed before the reply was received. In the case of the latter, you will get the 'Channel ended, no reply will be forthcoming'. This is especially common when you are sharing a channel and one flow of execution does something which breaks the channel while another is waiting for a reply. The first thing to do is to fix any incorrect channel usage, e.g.
You will also find things easier to manage if you use a dedicated channel for each consumer. In my applications I go one step further and don't share channels at all, but there is a cost - opening and closing a channel takes a little time and maintaining a larger number of channels increases the number of file handles and memory. I mitigate this by using a channel pool, similar to a database connection pool, but this does add extra complexity and is can still be slower than sharing a channel. The other thing you can do is make sure your code handles channel errors, by replacing them when they break. This won't prevent the original channel from erroring, but it will at least allow your application to recover. I'm not sure how easy any of this will be with NestJS though. |
Hi, @cressie176 . Thanks for your swift response. I didn't realize you had responded because I switched to another project. Noticed a moment ago. So, yeah, one of what you said is definitely correct. This particularly: "Yet another is that you have sent a command to RabbitMQ and are awaiting a reply, but the channel closed before the reply was received." I'm new to RMQ and didn't know this. So, in the case of NestJS, I have actually commented out the code that connects the microservices and, of course, the app starts without the errors. But when I copy and use one of the examples mentioned previously, I still get the error and it doesn't work. The example: ...
async function setupExchangeWithPromises() {
try {
const connection = await amqp.connect(configService.get('RMQ_URI'));
const channel = await connection.createChannel();
const exchangeName = 'WS';
const exchangeType = 'direct';
const options = { durable: true };
await channel.assertExchange(exchangeName, exchangeType, options);
await channel.close();
await connection.close();
} catch (error: any) {
console.error('Error:', error);
}
}
await setupExchangeWithPromises();
... I get a similar error (code): Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
errno: -54,
code: 'ECONNRESET',
syscall: 'read'
} |
Hi @power-f-GOD,
|
As all the suggestions above didn't work for me, I took the hard route/path: I ( |
I'm receiving this error:
This occurs because of a race condition happening where the order of operation is:
channel.cancel(consumerTag)
connection.close()
The connection ends up closing before cancel can be called on the channel. The error triggers because this promise is rejected before the return statement happens 2 lines later.
I'm not sure of the correct action to take here...I attempted to wrap the call to
_rpc
in anextTick
but that just seemed to shift the error. So far I've had the most success with putting:At the top of channel_model.js -- again, I'm not sure if that's the correct solution to this problem.
The text was updated successfully, but these errors were encountered: