apache / apache/pulsar-client-node

Producers or consumers may be closed after the client exits out of scope

オープン
#399 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
C++
スター
164
フォーク
98
PR マージ指標
30日以内にマージされた PR はありません

説明

Here is the reproduction code:
```js
const Pulsar = require('pulsar-client');

(async () => {
// Create a client
const client = new Pulsar.Client({
serviceUrl: 'pulsar://localhost:6650'
});

// Create a producer
const producer = await client.createProducer({
topic: 'persistent://public/default/my-topic',
});

const sendRecords = async () => {
// Send a message
await producer.send({
data: Buffer.from("hello")
});

console.log("sent hello")
setTimeout(()=>sendRecords(), 1000)
}


await sendRecords();
})();
```

The output would be like:
```
➜ node node index.js
sent hello
sent hello
sent hello
sent hello
sent hello
sent hello
sent hello
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^

[Error: Failed to send message: AlreadyClosed]

Node.js v18.19.0
```
After the client exits the outer function's scope, it will eventually be garbage collected. This closes the producers and causes the AlreadyClosed issue.

A workaround is to pass the client ref to the sendRecords function:
```js
const sendRecords = async (client) => {
// Send a message
await producer.send({
data: Buffer.from("hello")
});

console.log("sent hello")
setTimeout(()=>sendRecords(client), 1000)
}


await sendRecords(client);
```

And it works.

A better approach is to keep a reference to the client inside the producer or consumer. This way, as long as we hold a reference to the producer or consumer, the client object will not be garbage collected.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

ソースファイルやテストは指定されていません。まずローカルの Pulsar ブローカーに対して再現を実行し、次に Node.js クライアントにおける producer、consumer、client のライフタイム処理を追跡します。外側の関数スコープが終了した後も producer または consumer が client を使用可能な状態に保ち、継続的な送信中に AlreadyClosed が発生するのをリグレッションテストで防げれば完了です。

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

評価

技術スタック
javascript, node.js
領域
backend, distributed-systems
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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