project_chat_application icon indicating copy to clipboard operation
project_chat_application copied to clipboard

Server crash when sending message if user not found

Open Jeelislive opened this issue 3 months ago • 0 comments

In server/index.js, getUser(socket.id) can return undefined (e.g., if a client emits sendMessage before completing join or after disconnect). Accessing user.room then throws and can crash the server.

Steps to reproduce

  1. Connect a socket.
  2. Do not emit join, or disconnect quickly after joining.
  3. Emit sendMessage.

Expected behavior

  • Server validates the sender; if user is missing, it returns an error to the client and does not crash.

Actual behavior

  • Server attempts to access user.room and throws, potentially terminating the process.

Affected files

  • server/index.js (handler socket.on('sendMessage', ...))

Jeelislive avatar Sep 21 '25 13:09 Jeelislive