ReactiveX / rxjs

A reactive programming library for JavaScript
https://rxjs.dev
Apache License 2.0
30.6k stars 3k forks source link

WebSocketSubject has different behavior on Chrome Android when closing webSockets #6441

Open SundayDelight opened 3 years ago

SundayDelight commented 3 years ago

Bug Report

Current Behavior When closing a websocket on Chrome for Android, the WebSocketSubject calls its complete callback. When closing a websocket on Chrome for desktop, the WebSocketSubject calls its error callback.

Expected behavior Behavior should be consistent on both browsers.

Reproduction Create a WebSocketSubject connecting to a homemade server, subscribe to it so that the websocket actually connects. Then, from the server, close the connection with code 1000 (normal closure). WebSocketSubject on Chrome desktop will throw error while the one on Chrome Android will complete.

Environment

Additional context/Screenshots The Websocket server I used was one built from Qt, that simply calls the QWebSocket class close() method to trigger the callbacks of WebSocketSubject.

bever1337 commented 1 year ago

I suspect this comes down to an implementation detail of the browser. I couldn't find any open chromium tickets, but I found related, closed tickets. RxJS checks the wasClean flag of the websocket close event. There is no vendor-specific behavior. If wasClean, then close, else error. A WebSocket error and an RxJS observable error are similar, both indicate the stream has closed.

See: https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/dom/WebSocketSubject.ts#L350-L354