MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 disconnect listeners added

#1

Hi, I am getting this warning when I try to connect users to the socket.
It comes up after 8th user joining.

I have tried updating the maxListeners value in config\event.js

I have made a simple socket controller.

(node:40116) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 disconnect listeners added. Use emitter.setMaxListeners() to increase limit
    at _addListener (events.js:280:19)
    at Socket.addListener (events.js:297:10)
    at AdonisSocket.on (D:\xampp\htdocs\dsnew\node_modules\adonis-websocket\src\Socket\index.js:118:17)
    at ExtendedChannel.LifeCycle._onConnection (D:\xampp\htdocs\dsnew\node_modules\adonis-websocket\src\Channel\Mixins\LifeCycle.js:38:13)
    at Namespace.Channel.io.on (D:\xampp\htdocs\dsnew\node_modules\adonis-websocket\src\Channel\index.js:123:47)
    at emitOne (events.js:116:13)
    at Namespace.emit (events.js:211:7)
    at Namespace.emit (D:\xampp\htdocs\dsnew\node_modules\socket.io\lib\namespace.js:209:10)
    at D:\xampp\htdocs\dsnew\node_modules\socket.io\lib\namespace.js:177:14
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

Versions:

    "adonis-ace": "^3.0.7",
    "adonis-auth": "^1.0.5",
    "adonis-commands": "^2.1.5",
    "adonis-fold": "^3.0.3",
    "adonis-framework": "^3.0.10",
    "adonis-lucid": "^3.0.14",
    "adonis-middleware": "^1.0.11",
    "adonis-validation-provider": "^3.0.5",
    "adonis-websocket": "^1.0.3",
    "aws-sdk": "^2.382.0",
    "ffmpeg": "0.0.4",
    "json2csv": "^4.3.5",
    "mysql": "^2.16.0",
    "nodemailer": "^5.1.1",
    "php-serialize": "^2.1.0",
    "pushy": "^2.0.5",
    "request-promise": "^4.2.4",
    "shelljs": "^0.8.3",
    "twitter": "^1.7.1",
    "unescape": "^1.0.1",
    "youch": "^2.0.4"

My code:

socket.js

const Ws = use('Ws')
Ws.channel('/organisation_2', 'HeartbeatController')

HeartbeatController

'use strict'

class HeartbeatController {

  constructor (socket, request) {
    this.socket = socket
    this.request = request
    console.log('socket connected: ' + socket.id + ' at ' + new Date()) // eslint-disable-line
  }

  * onHeartbeat (payload, callback) {
    try {

      // Some db queries
      callback({ payload, error: false, message: 'success' })
    } catch (e) {
      console.log(e)
      callback({ payload, error: true, message: e.message })
    }
  }

  * onDisconnect (payload) {
    console.log('socket disconnected: ' + this.socket.id + ' at ' + new Date()) // eslint-disable-line
  }

}

module.exports = HeartbeatController

When I connect more than 100 users simultaneously none of them get a callback.

0 Likes

#2

One solution I found is by updating

node_modules\adonis-websocket\src\Socket\index.js

class AdonisSocket {

  constructor (io, socket) {
    this.io = io
    this.socket = socket
    this.parentContext = null

    this.socket.setMaxListeners(100) // this line.

    .....
1 Like