-
Notifications
You must be signed in to change notification settings - Fork 163
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
Make the network code compile #6262
Conversation
7480e1c
to
0944929
Compare
The handling of error codes is a somewhat hybrid solution. To put it nicely.
0944929
to
faa91d1
Compare
@@ -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()}; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
src/realm/error_codes.h
Outdated
RLM_ERR_WEBSOCKET_INAVALIDEXTENSION = 4409, | ||
RLM_ERR_WEBSOCKET_INTERNALSERVERERROR = 4410, | ||
RLM_ERR_WEBSOCKET_TLSHANDSHAKEFAILED = 4411, | ||
RLM_ERR_WEBSOCKET_RESOLVE_FAILED = 4400, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@danieltabacaru I made a new attempt. Perhaps better. |
@@ -403,6 +403,19 @@ void Connection::websocket_error_handler() | |||
m_websocket_error_received = true; | |||
} | |||
|
|||
namespace { |
There was a problem hiding this comment.
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
src/realm/sync/network/websocket.cpp
Outdated
@@ -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) { |
There was a problem hiding this comment.
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.
We should use |
I think this is better than the previous approach. |
src/realm/error_codes.hpp
Outdated
UnknownError = RLM_ERR_UNKNOWN, | ||
}; | ||
|
||
enum WebSocketError : int32_t { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
There was a problem hiding this 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.
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. |
Jørgen and I are working on merging the parent branch into this so the tests can run. |
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that was it!
error = SyncError(new_error_code, error.reason(), error.is_fatal); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
The handling of error codes is a somewhat hybrid solution. To put it nicely.