diff --git a/CHANGELOG.md b/CHANGELOG.md index e7c32b9cbfd..651aebfdc67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) ### 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. diff --git a/src/realm/error_codes.h b/src/realm/error_codes.h index 7faf9f69a61..4b0a85bcd87 100644 --- a/src/realm/error_codes.h +++ b/src/realm/error_codes.h @@ -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, diff --git a/src/realm/sync/network/default_socket.cpp b/src/realm/sync/network/default_socket.cpp index 6905b480c43..c2b69d64d25 100644 --- a/src/realm/sync/network/default_socket.cpp +++ b/src/realm/sync/network/default_socket.cpp @@ -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 { diff --git a/src/realm/sync/network/websocket.cpp b/src/realm/sync/network/websocket.cpp index a173a72fd4c..4a2668b0708 100644 --- a/src/realm/sync/network/websocket.cpp +++ b/src/realm/sync/network/websocket.cpp @@ -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; @@ -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"; diff --git a/src/realm/sync/network/websocket_error.hpp b/src/realm/sync/network/websocket_error.hpp index 2c0dbbd0bc7..6ec2fc7268b 100644 --- a/src/realm/sync/network/websocket_error.hpp +++ b/src/realm/sync/network/websocket_error.hpp @@ -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, diff --git a/src/realm/sync/noinst/client_impl_base.cpp b/src/realm/sync/noinst/client_impl_base.cpp index 1dc59827610..32f99d39374 100644 --- a/src/realm/sync/noinst/client_impl_base.cpp +++ b/src/realm/sync/noinst/client_impl_base.cpp @@ -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. diff --git a/src/realm/sync/noinst/server/server.cpp b/src/realm/sync/noinst/server/server.cpp index e317076d0d8..87f8c7e43c3 100644 --- a/src/realm/sync/noinst/server/server.cpp +++ b/src/realm/sync/noinst/server/server.cpp @@ -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) { @@ -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; @@ -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