Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

A client reauth over the same socket should not count against their max connections

クローズ 初心者向け
#342 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@MatthewHarrigan がすでに取り組んでいます。

2026年9月30日 から。

  • #341 @MatthewHarrigan による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
88/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, node.js

調査の方向性

lib/listener.js の Sockets.prototype.auth() から始めてください。issue では、再認証時に同じ socket がユーザーのインデックスに追加される箇所として特定されています。auth.index を有効にし、maxConnectionsPerUser を 2 に設定した、issue の再現テストを使用してください。1 つの開いた socket で再認証を繰り返しても接続数の上限を超えず、一方で別々の接続は引き続きカウントされれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug
Runtime

node

Runtime version

v24.18.1

Module version

v14.0.1

Last module version without issue

N/A

Used with

hapi application

Any other relevant information

See https://github.com/hapijs/nes/pull/341. I commented with a test that reproduces the issue on master:

it('does not count reauthentication towards the connections limit', async () => {

    const server = Hapi.server();

    server.auth.scheme('custom', internals.implementation);
    server.auth.strategy('default', 'custom');
    server.auth.default('default');

    await server.register({ plugin: Nes, options: { auth: { index: true, maxConnectionsPerUser: 2 } } });
    await server.start();

    const client = new Nes.Client(getUri(server.info));
    await client.connect({ reconnect: false, auth: { headers: { authorization: 'Custom john' } } });

    await client.reauthenticate({ headers: { authorization: 'Custom john' } });
    // a reauth is not a new connection
    await expect(client.reauthenticate({ headers: { authorization: 'Custom john' } })).to.not.reject();

    client.disconnect();
    await server.stop();
});
What are you trying to achieve or the steps to reproduce?

With auth.index: true, every reauthenticate() on an open connection pushes the same socket onto the user's index array again. Sockets.prototype.auth() in lib/listener.js doesn't check whether it's already there.

What was the result you got?

Multiple reauths due to token refresh can lead to disconnections due to hitting configured maxConnectionsPerUser when user only has 1 connection open.

An additional side effect is that a broadcast() targeted at a user will cause them to receive duplicate messages due to their socket being duplicated in the _byUser array.

What result did you expect?

I would expect only true connections (multiple tabs open for example) would count towards the limit.

主要言語
JavaScript
スター
502
フォーク
85
平均マージ
16日 16時間
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

hapijs/nes のほかの issue

hapijs/nes の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。