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

Server code improvements #250

Merged
merged 6 commits into from
Jul 14, 2023
Merged

Server code improvements #250

merged 6 commits into from
Jul 14, 2023

Conversation

achim-k
Copy link
Collaborator

@achim-k achim-k commented Jul 13, 2023

Public-Facing Changes

Refactor server code, improve multi-threading safety

Description

Addresses comments from foxglove/ws-protocol#491. These changes will be applied to that PR once this PR gets merged.

  • Fixes modifications to a class member being made while holding only a shared lock
  • Log an error if handler functions are not defined by server
  • Move text handlers into separate functions
  • Other refactoring / simplications

@achim-k achim-k requested a review from jtbandes July 13, 2023 19:26
Copy link
Member

@jtbandes jtbandes left a comment

Choose a reason for hiding this comment

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

👍

@@ -38,6 +38,29 @@
} \
}

namespace {

constexpr uint32_t Integer(const std::string_view str) {
Copy link
Member

Choose a reason for hiding this comment

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

this function should probably be named StringHash or something that actually explains what it does.

Is there any compile time guarantee that the strings we use it with actually hash to different values? I guess we would hope to get a compile error if it resulted in a switch with multiple identical cases?

edit: but I see we are not using switch..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed it and changed it back to a switch

Comment on lines 377 to 378
} catch (...) {
}
Copy link
Member

Choose a reason for hiding this comment

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

Why do nothing here? Seems like we should log an error if possible?

default: {
try {
const auto intOp = Integer(op);
if (intOp == SUBSCRIBE) {
Copy link
Member

Choose a reason for hiding this comment

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

can this be a switch?

inline bool Server<ServerConfiguration>::hasHandler(uint32_t op) const {
switch (op) {
case SUBSCRIBE:
return static_cast<bool>(_handlers.subscribeHandler);
Copy link
Member

Choose a reason for hiding this comment

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

nit: you can just do bool(...)

@achim-k achim-k enabled auto-merge (squash) July 14, 2023 13:54
@achim-k achim-k merged commit 7fbd1ab into main Jul 14, 2023
10 of 11 checks passed
@achim-k achim-k deleted the achim/server_improvements branch July 14, 2023 14:14
achim-k added a commit that referenced this pull request Jul 17, 2023
### Public-Facing Changes

Fix segfault due to invalid iterator

### Description
Fixes a segfault caused by using an invalid iterator as argument to
`std::unordered_map<...>::erase`. This regression was introduced in
#250.
achim-k added a commit that referenced this pull request Jul 25, 2023
### Public-Facing Changes

Fix specific exceptions not being caught

### Description
Fixes specific exceptions not being caught, leading to vague error
messages. This regression got introduced with #250.
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