gj / fastify-ws

MIT License
55 stars 11 forks source link

ECONNRESET #8

Closed 1Map closed 5 years ago

1Map commented 5 years ago

I get the following error message, just before disconnecting / Refreshing page / Socket Closing:

{"type":"Error","message":"read ECONNRESET","stack":"Error: read ECONNRESET\n at TCP.onread (net.js:622:25)","errno":"ECONNRESET","code":"ECONNRESET","syscall":"read"}

My code below:

Note that I first get the error message above and then my 'Client Disconnected' log message.

app.ready(err => {
    if (err) throw err

    app.log.info('Server started')

    app.ws.getUniqueID = function () {
        function s4() {
            return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1)
        }
        return s4() + s4() + '-' + s4()
    }

    app.ws
        .on('connection', socket => {
            socket.id = app.ws.getUniqueID()
            app.log.info('Client Connected: ' + socket.id)

            socket.on('message', msg => {
                socket.send(JSON.stringify({
                    from: socket.id,
                    to: socket.id,
                    msg: msg
                }))
            })

            socket.on('close', () => {
                app.log.info('Client Disconnected: ' + socket.id)
            })
        })
})
gj commented 5 years ago

Hey @1Map, I'm unable to reproduce this behavior. What versions of Node and Fastify are you running?