nest icon indicating copy to clipboard operation
nest copied to clipboard

Bug Report: ack Callback from Client not Received in NestJS @SubscribeMessage Handler

Open duc190604 opened this issue 5 months ago β€’ 4 comments
trafficstars

Is there an existing issue for this?

  • [x] I have searched the existing issues

Current behavior

When emitting a Socket.IO event with a callback from the client (i.e., emit(event, payload, ack)), the third parameter ack is not received in the NestJS gateway method decorated with @SubscribeMessage. Only two arguments are passed: the socket instance and the payload.

Minimum reproduction code

https://github.com/duc190604/bug_report

Steps to reproduce

How to Run and Test the Application πŸ”§ Start the Server (NestJS): Open terminal.

Navigate to the server directory.

Run the server with the appropriate command (e.g., npm run start:dev).

The server will be running at: http://localhost:3001/

πŸ’» Start the Client (React): Open a new terminal.

Navigate to the client directory.

Run the client with the appropriate command (e.g., npm start).

The client will be running at: http://localhost:3000/

🌐 Test WebSocket Connection

  1. Open the client in a browser: Go to: http://localhost:3000/

You should see a UI with:

Connection status (🟒 Connected or πŸ”΄ Disconnected)

An input field for typing messages

A "Send" button

  1. Test message sending: Type a message (e.g., Hello Server) in the input box

Press Enter or click the Send button

Wait for the server response displayed below the input

🧾 Check Client Logs (Browser Console): Open DevTools (press F12)

Watch for the following logs:

"Connected to server" when the connection is established

"Sending message: ..." when a message is sent

"Received acknowledgment: ..." when the server responds

πŸ–₯️ Check Server Logs (Terminal): In the terminal running the server, observe:

"Server is running on port 3001" after the server starts

"args: ..." when a message is received from the client ( and don't include ack)

Expected behavior

The ack callback function should be passed to the last parameter of the handler, and be callable from within NestJS so the server can send an acknowledgment to the client.

Package

  • [ ] I don't know. Or some 3rd-party package
  • [ ] @nestjs/common
  • [ ] @nestjs/core
  • [ ] @nestjs/microservices
  • [ ] @nestjs/platform-express
  • [ ] @nestjs/platform-fastify
  • [x] @nestjs/platform-socket.io
  • [x] @nestjs/platform-ws
  • [ ] @nestjs/testing
  • [x] @nestjs/websockets
  • [ ] Other (see below)

Other package

No response

NestJS version

11.1.3

Packages versions

platform-socket.io version : 11.1.3
platform-express version : 11.1.3
websockets version : 11.1.3
schematics version : 11.0.5
mongoose version : 11.0.3
passport version : 11.0.5
swagger version : 11.2.0
testing version : 11.1.1
common version : 11.1.3
config version : 4.0.2
core version : 11.1.3
jwt version : 11.0.0
cli version : 11.0.7

Node.js version

v22.13.0

In which operating systems have you tested?

  • [ ] macOS
  • [x] Windows
  • [ ] Linux

Other

No response

duc190604 avatar Jun 15 '25 15:06 duc190604

it looks like your repository https://github.com/duc190604/ChatApp_BE-NestJS is not public

micalevisk avatar Jun 15 '25 15:06 micalevisk

I’ve only included a placeholder link for now as I don’t have time to prepare a full reproduction. Please refer to the description above for a clear explanation of the issue.

duc190604 avatar Jun 15 '25 15:06 duc190604

Please provide a minimum reproduction repository. You can start one by running npm init nest in your terminal

why reproductions are required

micalevisk avatar Jun 15 '25 15:06 micalevisk

I updated minimum reproduction repository

duc190604 avatar Jun 15 '25 16:06 duc190604

Have you tried this https://github.com/nestjs/nest/issues/581#issuecomment-389267854

kamilmysliwiec avatar Jun 18 '25 12:06 kamilmysliwiec

Have you tried this #581 (comment)

Running the PR locally works well, and one is able to get the acknowledgement.

Image Image

kamaliki avatar Sep 30 '25 09:09 kamaliki