WebSocket connection is closed on client side but has status 101 in the Network tab (on Chrome)

102 Views Asked by At

I'm closing websocket connection on client side via button click and logging the event, as well as have 'webSocket.onClose' logging. Both log entries indicate that websocket was closed successfully, but it's status stays 101 in the web Inspector, on the Network tab of Chrome. When I reopen websocket connection, it just adds a new websocket entry into the network tab. Server side also seems to close the connection. My code in React JS is below. Is there anything wrong with my approach?

const newSocket = new WebSocket(webSocketUrl);
newSocket.onclose = (event) => {
        // Handle WebSocket closure and update the state
        console.log('WebSocket closed:', event.code, event.reason);
    };
render(<div>
  <Button
    onClick={() => socket?.close(4003, 'Clicked close socket button')}>
    {'Close Socket'}
  </Button>
 </div>)
    
0

There are 0 best solutions below