Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

serverSideEmit(..., callback) does not deliver events until heartbeat is triggered

Đang mở
#16 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

@Harjot2022 đang làm issue này rồi.

Từ ngày 22/3/2026.

  • #18 của @wangxpych — đã đóng, không merge

Đá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

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.0
  • socket.io: 4.8.x
  • pg: 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 LISTEN channel
  • 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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của socketio/socket.io-postgres-adapter

Tất cả issue của socketio/socket.io-postgres-adapter

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.