DoctorMcKay / node-steam-user

Allows interaction with the Steam network via the Steam client protocol
https://dev.doctormckay.com/forum/7-node-steam-user/
MIT License
892 stars 157 forks source link

Fix uncaught exceptions when reading and writing messages via TCP #475

Closed Sadzurami closed 2 months ago

Sadzurami commented 9 months ago

Exceptions here happens not often, but they are.

Examples:

Here we don't know where exactly error goes on.

Uncaught exception: Cannot read properties of undefined (reading 'write')

Error: Uncaught exception
    at process.<anonymous> (C:\project\dist\main.js)
    at process.emit (node:events:537:28)
    at process.processEmit [as emit] (C:\project\node_modules\signal-exit\index.js:199:34)
    at process._fatalException (node:internal/process/execution:167:25)
caused by: TypeError: Cannot read properties of undefined (reading 'write')
    at TCPConnection.send (C:\project\node_modules\steam-user\components\connection_protocols\tcp.js:165:15)
    at SteamUser._send (C:\project\node_modules\steam-user\components\03-messages.js:492:20)
    at Timeout._onTimeout (C:\project\node_modules\steam-user\components\09-logon.js:776:11)
    at listOnTimeout (node:internal/timers:564:17)
    at process.processTimers (node:internal/timers:507:7)

Here we can see, that error happened after logOff.

Uncaught exception: Cannot read properties of undefined (reading 'write')

Error: Uncaught exception
    at process.<anonymous> (C:\project\dist\main.js)
    at process.emit (node:events:537:28)
    at process.processEmit [as emit] (C:\project\node_modules\signal-exit\index.js:199:34)
    at process._fatalException (node:internal/process/execution:167:25)
caused by: TypeError: Cannot read properties of undefined (reading 'write')
    at TCPConnection.send (C:\project\node_modules\steam-user\components\connection_protocols\tcp.js:165:15)
    at SteamUser._send (C:\project\node_modules\steam-user\components\03-messages.js:492:20)
    at SteamUser._disconnect (C:\project\node_modules\steam-user\components\09-logon.js:501:9)
    at SteamUser.logOff (C:\project\node_modules\steam-user\components\09-logon.js:485:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)

ref: https://github.com/DoctorMcKay/node-steam-user/issues/392