Producers or consumers may be closed after the client exits out of scope
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, node.js
- Lĩnh vực
- backend, distributed-systems
Hướng nghiên cứu
Không có tệp mã nguồn hoặc bài kiểm thử nào được nêu tên. Hãy bắt đầu bằng cách chạy tái hiện với một broker Pulsar cục bộ, sau đó lần theo cách quản lý vòng đời của producer, consumer và client trong Node.js client; được xem là hoàn tất khi một producer hoặc consumer vẫn giữ cho client của nó có thể sử dụng được sau khi phạm vi của hàm bên ngoài kết thúc và một regression test ngăn AlreadyClosed xảy ra trong quá trình tiếp tục gửi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Here is the reproduction code:
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:
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.
- Ngôn ngữ chính
- C++
- Star
- 164
- Fork
- 99
- Merge trung bình
- 5 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 2
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/pulsar-client-node
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
apache/pulsar-client-node#477 ·
-
公司网络无法访问海外站点,如何解决? Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
apache/pulsar-client-node#455 · 3 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
apache/pulsar-client-node#432 · 2 reaction ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 38/100
apache/pulsar-client-node#431 · 3 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
apache/pulsar-client-node#429 · 1 bình luận ·
Tất cả issue của apache/pulsar-client-node
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
AXERA-TECH/ax-llm#77 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
games-on-whales/wolf#509 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
bug-unconfirmed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
NVIDIA/cuda-samples#453 ·