rpc-websockets icon indicating copy to clipboard operation
rpc-websockets copied to clipboard

process is hanging after calling client.close

Open Rinse12 opened this issue 1 year ago • 3 comments

Thank you for open sourcing this library. We're having this issue where the process is not exiting after stopping the client. We're on 7.6.0. This code should replicate the problem:

const WebSocket = require("rpc-websockets").Client;
const client = new WebSocket("ws://localhost:39652");
client.close();
console.log("Program should exit after this");

Rinse12 avatar Nov 05 '23 11:11 Rinse12

Hey, thanks!

The clients polls for connection with new WebSocket first and then issues the 'open' event afterwards. You can use close right after. What's the use-case for this, though?

It works like this:

var WebSocket = require('rpc-websockets').Client

const client = new WebSocket("ws://localhost:39652");

client.on('open', function() {
    console.log('socket opened')
    client.close();

    console.log("Program should exit after this");
})

mkozjak avatar Nov 13 '23 11:11 mkozjak

In the case the connection never gets established, I believe the process will be still hanging (if I remember correctly)

Rinse12 avatar Nov 13 '23 11:11 Rinse12

Please test if you get either the error or close event.

mkozjak avatar Nov 13 '23 11:11 mkozjak