sockjs / sockjs-client

WebSocket emulation - Javascript client
MIT License
8.43k stars 1.3k forks source link

Unable to reconnect to websocket, error handler function called #485

Closed sameerthekhans closed 5 years ago

sameerthekhans commented 5 years ago

Hi

I am using sockjs-client@1.1.4 with webstomp-client@1.2.0 in angular application.

When user logged in, I am connecting to websocket

const socket = new SockJS(url);
this.stompClient = Stomp.over(socket, { debug: false });
this.httpHeaders = {
  'Authorization': 'Bearer ' + authToken,
  'X-XSRF-TOKEN': this.csrfService.getCSRF('XSRF-TOKEN')
};
this.stompClient.connect(this.httpHeaders, () => {
 //Success handler
}, err => //error handler)

When user logout, I am disconnecting to websocket this.stompClient.disconnect();

The above code only works at initial time, after disconnecting I get this error

websocket.js?13c0:6 WebSocket connection to **MY IP AND PATH** failed: Error during WebSocket handshake: Unexpected response code: 500

and again reconnecting doen't work, It shows error in console, below is the error object { bubbles: false cancelable: false code: 2000 reason: "All transports failed" timeStamp: 1568461038120 type: "close" wasClean: false }

And one more thing, If I open my application multiple times (chrome tabs) same error for connecting, and existing websocket connection also closed/failed

brycekahle commented 5 years ago

Clearly there is something wrong with the your server, hence the 500 error. This does not appear to be a client issue.