Skip to content

rpc: each failed login leaves its server connection open #759

Open

Description

@lionelhorn

When authentication fails in connect(), the connection stays open on the server, one more per retry, even after client.disconnect().

import { DirectClient, RpcKernel, RpcKernelBaseConnection, RpcKernelSecurity, Session } from '@deepkit/rpc';

class TokenSecurity extends RpcKernelSecurity {
    async authenticate(token: any): Promise<Session> {
        if (token === 'secret') return new Session('user', token);
        throw new Error('Authentication failed');
    }
}

const kernel = new RpcKernel([{ provide: RpcKernelSecurity, useClass: TokenSecurity, scope: 'rpc' }]);
const openConnections = new Set<RpcKernelBaseConnection>();
kernel.onConnection(connection => {
    openConnections.add(connection);
    connection.onClose.then(() => openConnections.delete(connection));
});

const client = new DirectClient(kernel);
client.token.set('wrong');
for (let attempt = 0; attempt < 3; attempt++) {
    await client.connect().catch((error: Error) => console.log(error.message)); // 'Authentication failed'
}
await client.disconnect();
await new Promise(resolve => setTimeout(resolve, 20));
console.log(openConnections.size);
// actual: 3, should be: 0 (with the right token, connect() then disconnect() leaves 0)

Master 0bb9fba, Node 26.13.0.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions