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

call action handlers after action, in c++ server #850

Merged
merged 2 commits into from
Oct 22, 2024

Conversation

paulsohn
Copy link
Contributor

@paulsohn paulsohn commented Oct 22, 2024

Changelog

Guarantees that action handlers in C++ ws server are called after the action has been applied.

Docs

https://github.com/orgs/foxglove/discussions/1049

Description

Problem

In C++ server, handlers for below events are called before the internal states are fully updated:

  • subscribe
  • unsubscribe
  • client advertise
  • client unadvertise
  • subscribe connection graph

As a consequence, some user behavior does not work as expected, such as calling sendMessage() for messages of the requested topic inside of subscription handler. When subscription handler is called, the internal state does not recognize the requested topic as subscribed, and sendMessage() filters out this unsubscribed topic.

This seems to be a bug rather than a spec, because typescript and python server implementations calls listener/emit event after all internal tables are updated.

Changes

For the above events, switch the order of handler call and internal map updates.

https://linear.app/foxglove/issue/FG-9181/c-foxglove-websocket-server-ambiguous-handler-invoke-timing

{
std::unique_lock<std::shared_mutex> clientsLock(_clientsMutex);
_clients.at(hdl).advertisedChannels.emplace(channelId);
clientPublications.emplace(channelId, advertisement);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this one needs to be under the lock, it's a local variable

@jtbandes jtbandes requested a review from achim-k October 22, 2024 16:43
@jtbandes
Copy link
Member

Thanks!

@jtbandes jtbandes merged commit d4f5c73 into foxglove:main Oct 22, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants