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

Run client handler functions in separate thread #165

Merged
merged 1 commit into from
Feb 17, 2023

Conversation

achim-k
Copy link
Collaborator

@achim-k achim-k commented Feb 16, 2023

Public-Facing Changes

  • Run client handlers in separate thread

Description
Builds on top of #156

So far we have executed client handler functions in the websocket server thread. This could cause issues with clients not receiving messages anymore while a longer-running handler function was executing. This PR fixes this by handler functions being executed in a separate thread.

Fixes #164
Fixes FG-2029

: logTime(logTime)
, publishTime(publishTime)
, sequence(sequence)
, advertisement(advertisement)
, dataLength(dataLength)
, data(data) {}
, data(dataLength) {
std::memcpy(data.data(), rawData, dataLength);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the additional copy worth it? We should test on a low-power platform like a Jetson Nano.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have to do a copy now since we call the handler in a different thread and the pointer to the original data is likely not valid anymore.


ClientMessage(uint64_t logTime, uint64_t publishTime, uint32_t sequence,
const ClientAdvertisement& advertisement, size_t dataLength, const uint8_t* data)
const ClientAdvertisement& advertisement, size_t dataLength, const uint8_t* rawData)
: logTime(logTime)
, publishTime(publishTime)
, sequence(sequence)
, advertisement(advertisement)
Copy link
Contributor

@jhurliman jhurliman Feb 16, 2023

Choose a reason for hiding this comment

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

This is now a copy, but I'm assuming ClientAdvertisement is relatively cheap to copy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I think so too. At this stage I would rather have an extra copy then some hard to find bug. But yes, there is definitely potential for improvement later on

Base automatically changed from achim/decouple_server_implementation to main February 17, 2023 18:10
@achim-k achim-k force-pushed the achim/client_handlers_separate_thread branch from 82c53b3 to 4d512fe Compare February 17, 2023 18:11
@achim-k achim-k enabled auto-merge (squash) February 17, 2023 18:11
@achim-k achim-k merged commit 997adb9 into main Feb 17, 2023
@achim-k achim-k deleted the achim/client_handlers_separate_thread branch February 17, 2023 18:15
achim-k added a commit that referenced this pull request Apr 28, 2023
…210)

### Public-Facing Changes
None

### Description
- Refactors the way handler functions are run in a separate thread. It's
better to do that in a unified way in the server rather than doing that
for ROS 1 & 2 differently as it was implemented in #165
- Catch exeptions thrown in handler functions and send status message to
client

Fixes #148
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.

None yet

2 participants