Skip to content

incompatible with socket.io@3 and @4 - Exception thrown "TypeError: Cannot read property 'on' of undefined" #649

@frostmar

Description

@frostmar

The socket.io probe https://github.com/RuntimeTools/appmetrics/blob/master/probes/socketio-probe.js works fine with socket.io@2

However socket.io was rewritten for it's v3 and v4. The socket.io interface has changed slightly, causing the following exception to be thrown when socket.io is require'd and the probe attempts to hook in:

FATAL Node server exiting due to exception: TypeError: Cannot read property 'on' of undefined
                        at C:\firefly\repos\firefly-ui\node_modules\appmetrics\lib\aspect.js:56:26
                        at Array.forEach (<anonymous>)
                        at Object.exports.before (C:\firefly\repos\firefly-ui\node_modules\appmetrics\lib\aspect.js:55:9)
                        at SocketioProbe.attach (C:\firefly\repos\firefly-ui\node_modules\appmetrics\probes\socketio-probe.js:79:12)


I've done a little debugging and can see:

  • socket.io@2 exports a function with a prototype containing the methods the probe wants to patch.

  • socket.io@4 exports a factory function. The class is available as as export .Server (ie requre('socket.io').Server) however it's now a proper javascript Class, and it's constructor can't be hooked in the way used previously.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions