{"id":"db8f2d9db75f5576","repo":"socketio/socket.io","slug":"string-ev-is-a-reserved-event-name","errorCode":null,"errorMessage":"\"${String(ev)}\" is a reserved event name","messagePattern":"\"(.+?)\" is a reserved event name","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/socket.io-postgres-emitter/lib/index.ts","lineNumber":428,"sourceCode":"    });\n    await this.emitter.pool.query(\"SELECT pg_notify($1, $2)\", [\n      this.emitter.channel,\n      headerPayload,\n    ]);\n  }\n\n  /**\n   * Emits to all clients.\n   *\n   * @return Always true\n   * @public\n   */\n  public emit<Ev extends EventNames<EmitEvents>>(\n    ev: Ev,\n    ...args: EventParams<EmitEvents, Ev>\n  ): true {\n    if (RESERVED_EVENTS.has(ev)) {\n      throw new Error(`\"${String(ev)}\" is a reserved event name`);\n    }\n\n    // set up packet object\n    const data = [ev, ...args];\n    const packet = {\n      type: 2, // EVENT\n      data: data,\n      nsp: this.emitter.nsp,\n    };\n\n    const opts = {\n      rooms: [...this.rooms],\n      flags: this.flags,\n      except: [...this.exceptRooms],\n    };\n\n    this.publish({\n      type: EventType.BROADCAST,","sourceCodeStart":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/socketio/socket.io/blob/ae7fb46e08c5ed964b4a1ea8b1703e816511598e/packages/socket.io-postgres-emitter/lib/index.ts#L410-L446","documentation":"Thrown by the postgres-emitter's BroadcastOperator.emit() when the event name is in the emitter's RESERVED_EVENTS set (connect, connect_error, disconnect, disconnecting, newListener, removeListener). Emitters publish to other servers, and reserved names are reserved by the protocol; broadcasting them would be ambiguous and could corrupt lifecycle handling on receivers.","triggerScenarios":"Calling emitter.emit('connect'), emitter.to(room).emit('disconnect'), or any emit() with one of the six reserved event names on the socket.io-postgres-emitter.","commonSituations":"Using the postgres emitter to fan out a 'disconnect'/'connect' notification to all nodes instead of a custom event name; copy-pasting client event names into emitter calls; or a new reserved event added in a newer version.","solutions":["Rename your broadcast event to a non-reserved name (e.g. 'user:disconnected').","If you intend to notify other nodes about lifecycle changes, use a dedicated custom event consumed server-side.","Check RESERVED_EVENTS (exported from the package) before emitting if event names are dynamic."],"exampleFix":"// before\nemitter.emit('disconnect', { userId });\n\n// after\nemitter.emit('user:disconnected', { userId });","handlingStrategy":"validation","validationCode":"import { RESERVED_EVENTS } from 'socket.io-postgres-emitter';\nfunction assertNotReserved(ev){ if(RESERVED_EVENTS.has(ev)) throw new Error(ev+' is reserved'); }","typeGuard":"import { RESERVED_EVENTS } from 'socket.io-postgres-emitter';\nfunction isEmittable(ev){ return !RESERVED_EVENTS.has(ev); }","tryCatchPattern":null,"preventionTips":["Avoid broadcasting connect/connect_error/disconnect/disconnecting/newListener/removeListener via the emitter.","Use a custom event name for cluster lifecycle notifications.","Re-check the reserved set after package upgrades."],"tags":["emitter","postgres","reserved-events","broadcast"],"analyzedSha":"ae7fb46e08c5ed964b4a1ea8b1703e816511598e","analyzedAt":"2026-08-03T19:08:14.127Z","schemaVersion":2}