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

Make the network code compile #6262

Merged
merged 13 commits into from
Feb 24, 2023

Conversation

jedelbo
Copy link
Contributor

@jedelbo jedelbo commented Feb 1, 2023

The handling of error codes is a somewhat hybrid solution. To put it nicely.

@cla-bot cla-bot bot added the cla: yes label Feb 1, 2023
@jedelbo jedelbo force-pushed the je/fix-websocket branch 2 times, most recently from 7480e1c to 0944929 Compare February 2, 2023 14:17
The handling of error codes is a somewhat hybrid solution. To put it
nicely.
@@ -412,29 +425,37 @@ bool Connection::websocket_closed_handler(bool was_clean, Status status)
return bool(m_websocket);
}

auto&& status_code = status.code();
std::error_code error_code{static_cast<int>(status_code), websocket::websocket_close_status_category()};
Copy link
Collaborator

Choose a reason for hiding this comment

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

the sync_session expects the websocket_close_status_category. Why not have a category for websocket error/close codes instead of the dummy category?

std::error_code error_code{static_cast<int>(status_code), websocket::websocket_close_status_category()};
int status_code = status.code();
std::error_code error_code;
if (status_code == ErrorCodes::SystemError) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this check really needed?

RLM_ERR_WEBSOCKET_INAVALIDEXTENSION = 4409,
RLM_ERR_WEBSOCKET_INTERNALSERVERERROR = 4410,
RLM_ERR_WEBSOCKET_TLSHANDSHAKEFAILED = 4411,
RLM_ERR_WEBSOCKET_RESOLVE_FAILED = 4400,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We could consider adding a new enum just for websocket related error/close codes and remove the one in error_codes.hpp. Wouldn't that work?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, merge the ones here with WebSocketError since they all fit together

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess the main problem is that the codes will have new values, since 1xxx may be be used already for example. For server values, we could translate them in websocket.cpp and pass the new values along. Of course, a custom websocket implementation would have to do the same.

@jedelbo
Copy link
Contributor Author

jedelbo commented Feb 3, 2023

@danieltabacaru I made a new attempt. Perhaps better.

@@ -403,6 +403,19 @@ void Connection::websocket_error_handler()
m_websocket_error_received = true;
}

namespace {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is not needed anymore

@@ -1109,10 +1109,10 @@ class CloseStatusErrorCategory : public std::error_category {
{
// Converts an error_code to one of the pre-defined status codes in
// https://tools.ietf.org/html/rfc6455#section-7.4.1
if (error_code == 1000 || error_code == 0) {
return ErrorCodes::error_string(ErrorCodes::OK);
if (error_code == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think a value of 0 is not possible anymore. This was used when ErrorCodes::OK was 0 and there was no WebSocket_OK but I see you addressed that. I think you don't need to handle this in a special way anymore.

@danieltabacaru
Copy link
Collaborator

We should use realm_web_socket_errno_e instead of status_error_code_e in realm.h for realm_sync_socket_callback_complete and realm_sync_socket_websocket_closed

@danieltabacaru
Copy link
Collaborator

I think this is better than the previous approach.

UnknownError = RLM_ERR_UNKNOWN,
};

enum WebSocketError : int32_t {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to keep this in the ErrorCodes namespace? Should we just move these into src/realm/sync/network/websocket.hpp as a regular error enum? I think error_codes.hpp should be for errors we want users/sdks to have to handle - these seem like more internal status codes specific to the websocket implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds like a good idea. Added the change.

@jedelbo jedelbo requested a review from jbreams February 20, 2023 12:05
Copy link
Contributor

@jbreams jbreams left a comment

Choose a reason for hiding this comment

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

I really really strongly deeply don't like it that we've added std::error_code to Status, but it doesn't look like that was not done as part of this PR. So, LGTM when the tests pass.

Copy link
Contributor

@michael-wb michael-wb left a comment

Choose a reason for hiding this comment

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

The changes look good, but this branch likely needs a pull from the parent, since it's still using an old version of the install_baas.sh script, which is causing the object-store-tests to fail to start.

@jedelbo
Copy link
Contributor Author

jedelbo commented Feb 23, 2023

I really really strongly deeply don't like it that we've added std::error_code to Status, but it doesn't look like that was not done as part of this PR. So, LGTM when the tests pass.

I agree. This was done as a way of adapting to the new exception system without re-implementing the whole sync code (#5462 some 10 months ago). This should definitely be changed at some point in the future.

@danieltabacaru
Copy link
Collaborator

Jørgen and I are working on merging the parent branch into this so the tests can run.

Copy link
Contributor

@michael-wb michael-wb left a comment

Choose a reason for hiding this comment

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

I believe the missing restart_session is causing the redirect failure.

}
if (error_code == sync::websocket::WebSocketError::websocket_unauthorized ||
error_code == sync::websocket::WebSocketError::websocket_abnormal_closure ||
error_code == sync::websocket::WebSocketError::websocket_moved_permanently) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing the restart_session that is passed into u->refresh_custom_data()

Copy link
Collaborator

Choose a reason for hiding this comment

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

that was it!

Comment on lines +702 to +703
error = SyncError(new_error_code, error.reason(), error.is_fatal);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Also set error.is_unrecognized_by_client = true;, since this was being done before.

Copy link
Collaborator

Choose a reason for hiding this comment

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

this should not be a problem, since these errors (coarse-grained websocket errors) are recognized by the client

@danieltabacaru danieltabacaru merged commit 650865c into je/exception-unification-merge Feb 24, 2023
@danieltabacaru danieltabacaru deleted the je/fix-websocket branch February 24, 2023 07:03
@kiburtse kiburtse mentioned this pull request Mar 3, 2023
3 tasks
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants