deepstreamIO / deepstream.io

deepstream.io server

Home Page:https://deepstreamio.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Server crash on Type error

redlock opened this issue · comments

Hello,
There server crashed with this stack trace:

TypeError: Cannot read property '1' of undefined
at Object.exports.getMessage (/src/connection-endpoint/websocket/text/text-protocol/message-builder.ts:218:42)
at TextWSSocketWrapper.getMessage (/src/connection-endpoint/websocket/text/socket-wrapper-factory.ts:12:31)
at TextWSSocketWrapper.sendMessage (/src/connection-endpoint/base/socket-wrapper.ts:59:32)
at MessageDistributor.distribute (/src/utils/message-distributor.ts:21:21)
at MessageProcessor.onPermissionResponse (/src/utils/message-processor.ts:104:12)
at ConfigPermission.canPerformAction (/src/services/permission/valve/config-permission.ts:92:7)
at MessageProcessor.process (/src/utils/message-processor.ts:68:32)
at TextWSSocketWrapper.unauthenticatedSocketWrapper.onMessage (/src/connection-endpoint/base/connection-endpoint.ts:298:12)
at WebSocket.websocket.on (/src/services/http/node/node-http.ts:144:25)at WebSocket.emit (events.js:198:13)
--
stream | stderr

Before that it logged this message:
{ topic: 1, action: 1, originalTopic: 3 } false

UNKNOWN_TOPIC | AUTH

This happened in high load conditions using Records.

Thanks

So after digging into deepstream server code a bit the bug is apparent:

  if (!BUILDERS[message.topic] || !BUILDERS[message.topic][message.action]) {
    console.log(message, isAck)
  }
  const builder = BUILDERS[message.topic][message.action]
  if (!builder) {
    console.trace('missing builder for', message)
    return ''
  }

In the above code the server crashes when trying to find a builder with topic 1 which doesn't exist. Then when trying to access it with message.action you get the crash. There should be a condition to avoid this above it or just return in the earlier if statement.

hello!

Yeah that seems to be the case. Generally the text protocol is more of a best effort to have compatibility with older SDKs. But if you raise a fix I would be happy to merge it in!

Submitted a pull request. However, since I am not familiar with the context of where this function will be used I have returned an empty string (as was returned in a later line in the function). Please check it and review whether returning any empty string is safe. Thanks