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

Fix race condition in rpc client / test #1829

Merged
merged 13 commits into from
Oct 12, 2023
Merged

Fix race condition in rpc client / test #1829

merged 13 commits into from
Oct 12, 2023

Conversation

geoknee
Copy link
Contributor

@geoknee geoknee commented Oct 12, 2023

Closes #1749

There are a number of ways to solve this issue (essentially that the ObjectiveCompleted event can fire before an event listener is registered for it). One would be to cache completed objectives in the client (which is how the go rpc client does it).

I went another way, since that solution will only work if the event fired after the client itself is started. Here we attach the listener and perform a static query for the information straight afterward (with this being abstracted inside the rpc client).

Further, since we do not have a query path for objectives, I have flipped over the events and queries to be channel-centric and not objective-centric. This is mostly justified by expediency, but I think also it simplifies the API to not have objectives as an additional concept for developers to understand.

  • We may want to make a similar change to the go rpc client
  • at the reviewer's request I can pinch off some of the side effects of this PR: e.g. the colorized / human friendly logs

@netlify
Copy link

netlify bot commented Oct 12, 2023

Deploy Preview for nitro-payment-demo canceled.

Name Link
🔨 Latest commit 6e06584
🔍 Latest deploy log https://app.netlify.com/sites/nitro-payment-demo/deploys/6527fab19943a3000893fc28

@netlify
Copy link

netlify bot commented Oct 12, 2023

👷 Deploy Preview for nitrodocs processing.

Name Link
🔨 Latest commit 6e06584
🔍 Latest deploy log https://app.netlify.com/sites/nitrodocs/deploys/6527fab1509e840008eab99a

Comment on lines +69 to +72
h := tint.NewHandler(w, &tint.Options{
Level: level,
TimeFormat: time.Kitchen,
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

gives output like this:
Screenshot 2023-10-12 at 10 52 14

* @param objectiveId - The channel id to wait for
* @param status - The channel id to wait for (e.g. Ready or Closing)
*/
WaitForLedgerChannelToHaveStatus(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: could change the function name to WaitForLedgerChannelStatus to be a bit more concise

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}
);
});
const ledger = await this.GetLedgerChannel(channelId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there need for both this GetLedgerChannel call and the same one above nested inside the Notifications handler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What I am trying to do here is make it impossible for there to be a race condition. So the approach is,
Step 1: register a handler in case the event has not yet happened (if it already happened, this will never fire)
Step 2: make a static query in case the event has already happened.

Which should result in the promise resolving whenever the event fires / was fired.

Does that make sense?

@geoknee geoknee merged commit 880c8b5 into main Oct 12, 2023
8 checks passed
@geoknee geoknee deleted the disable-ts-rpc-test branch October 12, 2023 14:47
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.

RPC Client: WaitForObjective sometimes never resolves
2 participants