Skip to content

Commit

Permalink
Report a distinct error code for sync connection timeouts (#6932)
Browse files Browse the repository at this point in the history
The same error code was used for both timeouts and other connection failures,
and the error reported always had an empty message.
  • Loading branch information
tgoyne authored Aug 29, 2023
1 parent a678c36 commit f47e0bf
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Enhancements
* <New feature description> (PR [#????](https://github.com/realm/realm-core/pull/????))
* None.
* Add a distinct error code for timeouts (SyncConnectTimeout) rather than using the same one as for less transient failures ([PR #6932](https://github.com/realm/realm-core/pull/6932)).

### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
Expand Down
2 changes: 2 additions & 0 deletions src/realm/error_codes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ ErrorCategory ErrorCodes::error_categories(Error code)
return ErrorCategory().set(ErrorCategory::runtime_error).set(ErrorCategory::sync_error);

case SyncConnectFailed:
case SyncConnectTimeout:
case SyncProtocolNegotiationFailed:
case TlsHandshakeFailed:
return ErrorCategory()
Expand Down Expand Up @@ -383,6 +384,7 @@ static const MapElem string_to_error_code[] = {
{"SyncClientResetRequired", ErrorCodes::SyncClientResetRequired},
{"SyncCompensatingWrite", ErrorCodes::SyncCompensatingWrite},
{"SyncConnectFailed", ErrorCodes::SyncConnectFailed},
{"SyncConnectTimeout", ErrorCodes::SyncConnectTimeout},
{"SyncInvalidSchemaChange", ErrorCodes::SyncInvalidSchemaChange},
{"SyncPermissionDenied", ErrorCodes::SyncPermissionDenied},
{"SyncProtocolInvariantFailed", ErrorCodes::SyncProtocolInvariantFailed},
Expand Down
19 changes: 10 additions & 9 deletions src/realm/error_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,16 @@ typedef enum realm_errno {
RLM_ERR_SYNC_CLIENT_RESET_REQUIRED = 1032,
RLM_ERR_SYNC_COMPENSATING_WRITE = 1033,
RLM_ERR_SYNC_CONNECT_FAILED = 1034,
RLM_ERR_SYNC_INVALID_SCHEMA_CHANGE = 1035,
RLM_ERR_SYNC_PERMISSION_DENIED = 1036,
RLM_ERR_SYNC_PROTOCOL_INVARIANT_FAILED = 1037,
RLM_ERR_SYNC_PROTOCOL_NEGOTIATION_FAILED = 1038,
RLM_ERR_SYNC_SERVER_PERMISSIONS_CHANGED = 1039,
RLM_ERR_SYNC_USER_MISMATCH = 1040,
RLM_ERR_TLS_HANDSHAKE_FAILED = 1041,
RLM_ERR_WRONG_SYNC_TYPE = 1042,
RLM_ERR_SYNC_WRITE_NOT_ALLOWED = 1043,
RLM_ERR_SYNC_CONNECT_TIMEOUT = 1035,
RLM_ERR_SYNC_INVALID_SCHEMA_CHANGE = 1036,
RLM_ERR_SYNC_PERMISSION_DENIED = 1037,
RLM_ERR_SYNC_PROTOCOL_INVARIANT_FAILED = 1038,
RLM_ERR_SYNC_PROTOCOL_NEGOTIATION_FAILED = 1039,
RLM_ERR_SYNC_SERVER_PERMISSIONS_CHANGED = 1040,
RLM_ERR_SYNC_USER_MISMATCH = 1041,
RLM_ERR_TLS_HANDSHAKE_FAILED = 1042,
RLM_ERR_WRONG_SYNC_TYPE = 1043,
RLM_ERR_SYNC_WRITE_NOT_ALLOWED = 1044,

RLM_ERR_SYSTEM_ERROR = 1999,

Expand Down
1 change: 1 addition & 0 deletions src/realm/error_codes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class ErrorCodes {
SyncClientResetRequired = RLM_ERR_SYNC_CLIENT_RESET_REQUIRED,
SyncCompensatingWrite = RLM_ERR_SYNC_COMPENSATING_WRITE,
SyncConnectFailed = RLM_ERR_SYNC_CONNECT_FAILED,
SyncConnectTimeout = RLM_ERR_SYNC_CONNECT_TIMEOUT,
SyncInvalidSchemaChange = RLM_ERR_SYNC_INVALID_SCHEMA_CHANGE,
SyncPermissionDenied = RLM_ERR_SYNC_PERMISSION_DENIED,
SyncProtocolInvariantFailed = RLM_ERR_SYNC_PROTOCOL_INVARIANT_FAILED,
Expand Down
6 changes: 4 additions & 2 deletions src/realm/sync/noinst/client_impl_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,10 @@ void Connection::handle_connect_wait(Status status)

REALM_ASSERT_EX(m_state == ConnectionState::connecting, m_state);
logger.info("Connect timeout"); // Throws
involuntary_disconnect(SessionErrorInfo{Status{ErrorCodes::SyncConnectFailed, status.reason()}, IsFatal{false}},
ConnectionTerminationReason::sync_connect_timeout); // Throws
involuntary_disconnect(
SessionErrorInfo{Status{ErrorCodes::SyncConnectTimeout, "Sync connection was not fully established in time"},
IsFatal{false}},
ConnectionTerminationReason::sync_connect_timeout); // Throws
}


Expand Down

0 comments on commit f47e0bf

Please sign in to comment.