-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(satellite): clients overload the server on fatal errors (#518)
Make better use of the back off strategy for reconnecting and expose back off configuration to the app Stop trying to reconnect to electric on fatal errors.
- Loading branch information
Showing
8 changed files
with
239 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"electric-sql": patch | ||
--- | ||
|
||
prevent reconnect loop of doom on fatal errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { SatelliteError, SatelliteErrorCode } from '../util' | ||
import Log from 'loglevel' | ||
|
||
const fatalErrorDescription = | ||
"Client can't connect with the server after a fatal error. This can happen due to divergence between local client and server. Use developer tools to clear the local database, or delete the database file. We're working on tools to allow recovering the state of the local database." | ||
|
||
const throwErrors = [ | ||
SatelliteErrorCode.INTERNAL, | ||
SatelliteErrorCode.FATAL_ERROR, | ||
] | ||
|
||
const fatalErrors = [ | ||
SatelliteErrorCode.INVALID_REQUEST, | ||
SatelliteErrorCode.UNKNOWN_SCHEMA_VSN, | ||
SatelliteErrorCode.AUTH_REQUIRED, | ||
] | ||
|
||
const outOfSyncErrors = [ | ||
SatelliteErrorCode.INVALID_POSITION, | ||
SatelliteErrorCode.BEHIND_WINDOW, | ||
SatelliteErrorCode.SUBSCRIPTION_NOT_FOUND, | ||
] | ||
|
||
export function isThrowable(error: SatelliteError) { | ||
return throwErrors.includes(error.code) | ||
} | ||
|
||
export function isFatal(error: SatelliteError) { | ||
return fatalErrors.includes(error.code) | ||
} | ||
|
||
export function isOutOfSyncError(error: SatelliteError) { | ||
return outOfSyncErrors.includes(error.code) | ||
} | ||
|
||
function logFatalErrorDescription() { | ||
Log.error(fatalErrorDescription) | ||
} | ||
|
||
export function wrapFatalError(error: SatelliteError) { | ||
logFatalErrorDescription() | ||
return new SatelliteError( | ||
SatelliteErrorCode.FATAL_ERROR, | ||
`Fatal error: ${error.message}. Check log for more information` | ||
) | ||
} |
Oops, something went wrong.