-
Notifications
You must be signed in to change notification settings - Fork 4
Description
I encountered a crash with the following error:
Error: java.lang.IllegalArgumentException: Code 1005 is reserved and may not be used.
After investigating the issue I found that the code is returned when the connection was closed but there wasn't any status code. In this case the error code is reserved and so the app crashes. It seems that the library should santise the code before closing the websocket connection as certain codes are reserved.
Code in question:
nativescript-plugins/packages/nativescript-websockets/bridge.android.ts
Lines 171 to 173 in 3decf93
| public onClosing(websocket: okhttp3.WebSocket, code: number, reason: string): void { | |
| websocket.close(code, reason); | |
| } |
I'm no expert in terms of the implementation here, however I checked the reserved status codes for websockets and I found the following: https://datatracker.ietf.org/doc/html/rfc6455#section-7.4.1. So based on this the following code might be applied:
onClosing(websocket, code, reason) {
const reserved = [1004, 1005, 1006, 1015];
const safeCode = reserved.includes(code) ? 1000 : code;
websocket.close(safeCode, reason);
}