Page MenuHomePhabricator

[services] Tunnelbroker - Add `waitUntilReady` function in AmqpManager
ClosedPublic

Authored by max on Aug 4 2022, 10:50 AM.
Tags
None
Referenced Files
F2158911: D4741.id15813.diff
Mon, Jul 1, 5:21 AM
F2157125: D4741.id15326.diff
Mon, Jul 1, 1:16 AM
Unknown Object (File)
Sun, Jun 30, 3:14 AM
Unknown Object (File)
Sat, Jun 29, 4:18 PM
Unknown Object (File)
Wed, Jun 26, 5:25 AM
Unknown Object (File)
Wed, Jun 26, 5:25 AM
Unknown Object (File)
Wed, Jun 26, 5:25 AM
Unknown Object (File)
Wed, Jun 26, 5:25 AM

Details

Summary

This diff is a part of the stack to fix the AMQP client reconnection issue.

The waitUntilReady function handles waiting for reconnection. This function uses on send() and ack() methods which send and acknowledge the message correspondingly.
The expected behavior is that we must wait while the connection/channel became available instead of returning an error immediately and stopping the execution.

Related linear task: ENG-1495

Test Plan

Successfully built using yarn run-tunnelbroker-service-in-sandbox command.
Passing all AMQP unit tests in the last diff D4749 in a stack.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

max held this revision as a draft.
max edited the test plan for this revision. (Show Details)
max added reviewers: karol, tomek.
max published this revision for review.Aug 4 2022, 4:51 PM
max edited the test plan for this revision. (Show Details)
tomek requested changes to this revision.Aug 5 2022, 5:53 AM

I don't think that this is the correct way of waiting for this condition to occur. First of all, it might never happen as access to amqpReady isn't synchronized. We should probably use some concurrency primitives rather than a sleep.

This revision now requires changes to proceed.Aug 5 2022, 5:53 AM
In D4741#136854, @tomek wrote:

I don't think that this is the correct way of waiting for this condition to occur. First of all, it might never happen as access to amqpReady isn't synchronized.

std::atomic<bool> amqpReady is an atomic variable and thread-safe and synchronized on the onReady, onError events in a follow-up D4744 diff (D4744 fixes the reconnection logic). This change needs to be projected as a part of the stack.

We should probably use some concurrency primitives rather than sleep.

We can use conditional variables for that for example or something like that, but it doesn't make sense to overengineering here because we will wait for a reconnection interval anyway and just check after it (please look at the D4744 part of the stack). It will make sense when we will use a variation timeout in a follow-up ENG-1381. So it can be part of these future changes.

tomek added inline comments.
services/tunnelbroker/src/Amqp/AmqpManager.cpp
153–160 ↗(On Diff #15326)

Can we simplify it?

This revision is now accepted and ready to land.Aug 9 2022, 9:11 AM

Rebase on master changes.
Simplify while loop.

max added inline comments.
services/tunnelbroker/src/Amqp/AmqpManager.cpp
153–160 ↗(On Diff #15326)

Can we simplify it?

Sure! Nice catch, thanks!

This revision was landed with ongoing or failed builds.Aug 22 2022, 6:37 AM
This revision was automatically updated to reflect the committed changes.
max marked an inline comment as done.
services/tunnelbroker/src/Amqp/AmqpManager.cpp
144–146

This probably can be just removed

max added inline comments.
services/tunnelbroker/src/Amqp/AmqpManager.cpp
144–146

This probably can be just removed

Yes, definitely! I've missed this and this diff is already landed.
That's why I've created a tiny diff to fix this. Sorry about that, we have a race condition for this comment ).