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

feat: await for describe queue subscription when subscribing to queues #144

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

aymeric-agre
Copy link
Contributor

Context

Masterbag inbound process failing sometimes.
https://cubyn.slack.com/archives/C3US319PA/p1661962354346349
TL;DR inbound was correctly done but missing describe queue was raising an error when refreshing the list of in transit masterbags.

Description

Queue with meta without any describe queue will most likely lead to timeout when calling {qualifier}:describe hence I think we should wait for its subscription as well.

Queue with meta without any describe queue will lead
to timeout when calling {qualifier}:describe
hence we should await for its subscription as well
@@ -474,7 +475,7 @@ function Carotte(config) {
const exchangeName = getExchangeName(options);
const queueName = getQueueName(options, config);

return Promise.race([
return Promise.race(promises.concat([
Copy link
Contributor

@aymericbouzy aymericbouzy Sep 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum I think this is a breaking change. Previously the function was returning a Promise<ActualQueue> and is now returning a Promise<ActualQueue | DescribeQueue>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, will be better to just wait for it but still return the actual queue

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I was confused as of why we raced this promise with the other ones (timeout and "subscribeToActualQueue"). Just awaiting it should work just as well, right?

@aymericbouzy
Copy link
Contributor

I'm sorry, I did not quite understand how the issue was happening and how this change fixes it?

Since subscribing to a describe queue goes through carotte.subscribe as well, it also has the timeout : as long as we have a process.on("unhandledRejection", ...) (which is implemented by carotte-runtime and carotte-loader I believe), the error will cause the service to crash, no?

@aymeric-agre
Copy link
Contributor Author

Because describe queue creation is handled when base queue is created through a call to subscribe, I think it's quite important to keep this strong dependency.

Also I don't think having a global process.on('unhandledRejection', ...) is a good practice. Every promise created in a function should be awaited or at least have a callback to be handled properly.

@Guillaume-Pascal
Copy link

I agree with this:

Also I don't think having a global process.on('unhandledRejection', ...) is a good practice. Every promise created in a function should be awaited or at least have a callback to be handled properly.

From there, I think awaiting the "subscribe to describe" promise is the simplest solution.

But maybe we could also run it in parallel with the Promise.race(timeoutPromise, subscribeToActualQueuePromise) with something like this:

await Promise.all([
  Promise.race(timeoutPromise, subscribeToActualQueuePromise),
  subscribeToDescribeQueuePromise,
]);

This way we don't delay the "actual" subscribe as much, but it's probably only saving some milliseconds

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

Successfully merging this pull request may close these issues.

3 participants