Skip to content

Server crash when sending message if user not found #161

@Jeelislive

Description

@Jeelislive

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', ...))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions