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

RCORE-2210 Remove unused websocket too new/old errors #7917

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* None.

### Breaking changes
* None.
* The websocket error codes `websocket_client_too_old`, `websocket_client_too_new`, and `websocket_protocol_mismatch` along with their C API constants were removed. These corresponded to errors the legacy C++ server could have sent, but the baas sync server never did. Any platform networking implementations that surfaced these errors can report a `websocket_fatal_error` instead if an unknown error occurs during the websocket handshake. If a client connects that is too old or too new, it will finish the websocket handshake and then receive an in-band sync `ERROR` message that will be handled by the sync error handler. [PR #7917](https://github.com/realm/realm-core/pull/7917)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it's technically a breaking change, but I doubt any of the SDKs with platform networking care about this error (and I doubt they've ever seen it).


### Compatibility
* Fileformat: Generates files with format v24. Reads and automatically upgrade from fileformat v10. If you want to upgrade from an earlier file format version you will have to use RealmCore v13.x.y or earlier.
Expand Down
3 changes: 0 additions & 3 deletions src/realm/error_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,6 @@ typedef enum realm_web_socket_errno {
RLM_ERR_WEBSOCKET_UNAUTHORIZED = 4001,
RLM_ERR_WEBSOCKET_FORBIDDEN = 4002,
RLM_ERR_WEBSOCKET_MOVEDPERMANENTLY = 4003,
RLM_ERR_WEBSOCKET_CLIENT_TOO_OLD = 4004,
RLM_ERR_WEBSOCKET_CLIENT_TOO_NEW = 4005,
RLM_ERR_WEBSOCKET_PROTOCOL_MISMATCH = 4006,

RLM_ERR_WEBSOCKET_RESOLVE_FAILED = 4400,
RLM_ERR_WEBSOCKET_CONNECTION_FAILED = 4401,
Expand Down
25 changes: 1 addition & 24 deletions src/realm/sync/network/default_socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,32 +120,9 @@ class DefaultWebSocketImpl final : public DefaultWebSocket, public Config {
else {
error = WebSocketError::websocket_fatal_error;
was_clean = false;
if (!body.empty()) {
std::string_view identifier = "REALM_SYNC_PROTOCOL_MISMATCH";
auto i = body.find(identifier);
if (i != std::string_view::npos) {
std::string_view rest = body.substr(i + identifier.size());
// FIXME: Use std::string_view::begins_with() in C++20.
auto begins_with = [](std::string_view string, std::string_view prefix) {
return (string.size() >= prefix.size() &&
std::equal(string.data(), string.data() + prefix.size(), prefix.data()));
};
if (begins_with(rest, ":CLIENT_TOO_OLD")) {
error = WebSocketError::websocket_client_too_old;
}
else if (begins_with(rest, ":CLIENT_TOO_NEW")) {
error = WebSocketError::websocket_client_too_new;
}
else {
// Other more complicated forms of mismatch
error = WebSocketError::websocket_protocol_mismatch;
}
was_clean = true;
}
}
}

websocket_error_and_close_handler(was_clean, error, ec.message());
websocket_error_and_close_handler(was_clean, error, body.empty() ? ec.message() : body);
}
void websocket_protocol_error_handler(std::error_code ec) override
{
Expand Down
9 changes: 0 additions & 9 deletions src/realm/sync/network/websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,9 +979,6 @@ class WebSocket {
case WebSocketError::websocket_unauthorized:
case WebSocketError::websocket_forbidden:
case WebSocketError::websocket_moved_permanently:
case WebSocketError::websocket_client_too_old:
case WebSocketError::websocket_client_too_new:
case WebSocketError::websocket_protocol_mismatch:
break;
default:
error_code = 1008;
Expand Down Expand Up @@ -1180,12 +1177,6 @@ std::ostream& operator<<(std::ostream& os, WebSocketError code)
return "WebSocket: Forbidden";
case WebSocketError::websocket_moved_permanently:
return "WebSocket: Moved Permanently";
case WebSocketError::websocket_client_too_old:
return "WebSocket: Client Too Old";
case WebSocketError::websocket_client_too_new:
return "WebSocket: Client Too New";
case WebSocketError::websocket_protocol_mismatch:
return "WebSocket: Protocol Mismatch";

case WebSocketError::websocket_resolve_failed:
return "WebSocket: Resolve Failed";
Expand Down
3 changes: 0 additions & 3 deletions src/realm/sync/network/websocket_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ enum class WebSocketError {
websocket_unauthorized = RLM_ERR_WEBSOCKET_UNAUTHORIZED,
websocket_forbidden = RLM_ERR_WEBSOCKET_FORBIDDEN,
websocket_moved_permanently = RLM_ERR_WEBSOCKET_MOVEDPERMANENTLY,
websocket_client_too_old = RLM_ERR_WEBSOCKET_CLIENT_TOO_OLD,
websocket_client_too_new = RLM_ERR_WEBSOCKET_CLIENT_TOO_NEW,
websocket_protocol_mismatch = RLM_ERR_WEBSOCKET_PROTOCOL_MISMATCH,

websocket_resolve_failed = RLM_ERR_WEBSOCKET_RESOLVE_FAILED,
websocket_connection_failed = RLM_ERR_WEBSOCKET_CONNECTION_FAILED,
Expand Down
9 changes: 0 additions & 9 deletions src/realm/sync/noinst/client_impl_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,15 +594,6 @@ bool Connection::websocket_closed_handler(bool was_clean, WebSocketError error_c
ConnectionTerminationReason::ssl_certificate_rejected); // Throws
break;
}
case WebSocketError::websocket_client_too_old:
[[fallthrough]];
case WebSocketError::websocket_client_too_new:
[[fallthrough]];
case WebSocketError::websocket_protocol_mismatch: {
close_due_to_client_side_error({ErrorCodes::SyncProtocolNegotiationFailed, msg}, IsFatal{true},
ConnectionTerminationReason::http_response_says_fatal_error); // Throws
break;
}
case WebSocketError::websocket_fatal_error: {
// Error is fatal if the sync_route has already been verified - if the sync_route has not
// been verified, then use a non-fatal error and try to perform a location update.
Expand Down
23 changes: 4 additions & 19 deletions src/realm/sync/noinst/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1786,17 +1786,6 @@ class HTTPConnection {
Formatter& formatter = misc_buffers.formatter;
if (REALM_UNLIKELY(best_match == 0)) {
const char* elaboration = "No version supported by both client and server";
const char* identifier_hint = nullptr;
if (overall_client_max < server_min) {
// Client is too old
elaboration = "Client is too old for server";
identifier_hint = "CLIENT_TOO_OLD";
}
else if (overall_client_min > server_max) {
// Client is too new
elaboration = "Client is too new for server";
identifier_hint = "CLIENT_TOO_NEW";
}
auto format_ranges = [&](const auto& list) {
bool nonfirst = false;
for (auto range : list) {
Expand Down Expand Up @@ -1825,12 +1814,8 @@ class HTTPConnection {
formatter << "\n"; // Throws
formatter << "Client supports: "; // Throws
format_ranges(protocol_version_ranges); // Throws
formatter << "\n\n"; // Throws
formatter << "REALM_SYNC_PROTOCOL_MISMATCH"; // Throws
if (identifier_hint)
formatter << ":" << identifier_hint; // Throws
formatter << "\n"; // Throws
handle_400_bad_request({formatter.data(), formatter.size()}); // Throws
formatter << "\n"; // Throws
handle_400_bad_request({formatter.data(), formatter.size()}); // Throws
return;
}
m_negotiated_protocol_version = best_match;
Expand Down Expand Up @@ -3250,8 +3235,8 @@ void ServerFile::activate() {}
void ServerFile::register_client_access(file_ident_type) {}


auto ServerFile::request_file_ident(FileIdentReceiver& receiver, file_ident_type proxy_file, ClientType client_type)
-> file_ident_request_type
auto ServerFile::request_file_ident(FileIdentReceiver& receiver, file_ident_type proxy_file,
ClientType client_type) -> file_ident_request_type
{
auto request = ++m_last_file_ident_request;
m_file_ident_requests[request] = {&receiver, proxy_file, client_type}; // Throws
Expand Down
Loading