samchon / tgrid

TypeScript RPC (Remote Procedure Call) for WebSocket and Worker protocols
https://tgrid.com/
MIT License
141 stars 19 forks source link

WebServer.close() waits all clients to be disconnected. #45

Closed samchon closed 4 years ago

samchon commented 4 years ago

Summary

When call the WebServer.close() method and there's a client who is connecting to the WebServer, the method call would be completed until the client disconnects network connection with the server by itself. Therefore, it remained clients do not disconnect their connections by themselves, the WebServer.close() method would not be completed and fall into the forever sleep.

Code occuring the bug

const PORT = 10101;

export async function test_web_server_close(): Promise<void>
{
    let server: WebServer<null, null> = new WebServer();
    await server.open(PORT, acceptor => acceptor.accept(null));

    let connector: WebConnector<null, null> = new WebConnector(null, null);
    await connector.connect(`ws://127.0.0.1:${PORT}`);

    server.close().then(() =>
    {
        // it would be shown after 5,000 milliseconds later
        console.log("WOW");
    });
    await sleep_for(5000);
    await connector.close();
}