Skip to content

Crash due to reserved error codes #24

@dangrima90

Description

@dangrima90

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:

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions