serverSideEmit(..., callback) does not deliver events until heartbeat is triggered
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 52/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- postgresql, typescript
- Lĩnh vực
- backend, databases, distributed-systems
Hướng nghiên cứu
Start with the Postgres adapter's serverSideEmit(..., callback) and heartbeat or server discovery flow, using the minimal reproduction in the issue. Compare callback-based emits with emits without callbacks and verify that all connected servers receive the event and return acknowledgements before any dummy emit is sent.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Environment
@socket.io/postgres-adapter: 0.4.0socket.io: 4.8.xpg: 8.16.x- Node.js: 22
- PostgreSQL: 14.x
Problem description
When using serverSideEmit(..., callback), the callback is invoked with:
(err, responses) => {
console.log(err); // null
console.log(responses); // [] ← empty
}
The event is never delivered to any other server, and the handler (io.on(...)) is never triggered on them.
However, if each individual server sends at least one serverSideEmit() (even a dummy one), things start working — the events are delivered and acknowledged as expected.
Note: If
serverSideEmit()is used without a callback, the event is delivered to other servers even before they have sent any emits themselves. The issue only affects the ACK-based communication (serverSideEmit(..., callback)).
Root cause
The Postgres adapter does not deliver serverSideEmit(..., callback) events to other servers unless those servers have already started sending their own heartbeats.
Until a server sends a serverSideEmit():
- It is connected and listening on the correct
LISTENchannel - It can receive broadcast events without callback
- But it will not be discoverable by other servers for ACK-based communication (
serverSideEmit(..., callback))
As a result:
- The initiating server sends a request and waits for ACKs
- But other servers ignore the request because they don't recognize the source as active
- The callback returns with
responses = []
Minimal reproduction
// on all servers:
io.on("test-ack", (data, callback) => {
console.log("received:", data);
callback("ack from " + process.pid);
});
// on emitter server:
setTimeout(() => {
io.serverSideEmit("test-ack", "hello", (err, responses) => {
console.log("err:", err); // null
console.log("responses:", responses); // [] if heartbeat not yet started on other servers
});
}, 1000);
Workaround
Ensure that every server sends a dummy serverSideEmit() after startup to trigger the heartbeat:
io.serverSideEmit("__init__", "poke");
This ensures each server becomes discoverable by others and can participate in ACK-based messaging.
- Ngôn ngữ chính
- TypeScript
- Star
- 27
- Fork
- 9
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Không có mẫu pull request
- Không có hướng dẫn đóng góp
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 socketio/socket.io-postgres-adapter
-
Shutting down adapterĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 43/100
socketio/socket.io-postgres-adapter#13 · 4 bình luận · 1 reaction ·
-
question
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
socketio/socket.io-postgres-adapter#12 · 4 bình luận ·
Tất cả issue của socketio/socket.io-postgres-adapter
Issue tương tự
-
Table: Space fires onActivate in single-selection mode — the reference doc and the JSDoc disagreeĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
sidorares/react-x11-components#764 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
backnotprop/plannotator#1840 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
JoviDeCroock/pracht#432 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add: CNN en Espanol SDĐang mởapproved check:passed streams:add
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Hardware attribute name "app Connection Support" has inconsistent casingCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
walletbeat/walletbeat#1628 ·
Maintainer thường phản hồi trong vòng 1 ngày