add reasons for client.end() & fix issues (#944)

* add

add client.end() when ping.js fails

added reasons in encrypt.js

switched order of error event and client.end() in versionChecking.js

added an error emitter for keepAliveTimeout

* should be an Error object

* camalCase socketClosed
This commit is contained in:
usb 2021-12-24 09:55:13 -08:00 committed by GitHub
parent 601f86fc8f
commit 86dcbd5f3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 6 deletions

View file

@ -142,7 +142,7 @@ class Client extends EventEmitter {
this.socket.removeListener('close', endSocket)
this.socket.removeListener('end', endSocket)
this.socket.removeListener('timeout', endSocket)
this.emit('end', this._endReason || 'SocketClosed')
this.emit('end', this._endReason || 'socketClosed')
}
const onFatalError = (err) => {

View file

@ -15,7 +15,7 @@ module.exports = function (client, options) {
if (err) {
debug(err)
client.emit('error', err)
client.end()
client.end('encryptionSecretError')
return
}
if (options.haveCredentials) {
@ -30,7 +30,7 @@ module.exports = function (client, options) {
function onJoinServerResponse (err) {
if (err) {
client.emit('error', err)
client.end()
client.end('encryptionLoginError')
} else {
sendEncryptionKeyResponse()
}

View file

@ -14,7 +14,10 @@ module.exports = function (client, options) {
function onKeepAlive (packet) {
if (timeout) { clearTimeout(timeout) }
timeout = setTimeout(() => client.end(`client timed out after ${checkTimeoutInterval} milliseconds`), checkTimeoutInterval)
timeout = setTimeout(() => {
client.emit('error', new Error(`client timed out after ${checkTimeoutInterval} milliseconds`))
client.end('keepAliveError')
}, checkTimeoutInterval)
client.write('keep_alive', {
keepAliveId: packet.keepAliveId
})

View file

@ -12,8 +12,8 @@ module.exports = function (client, options) {
}
if (!versionRequired) { return }
client.end()
client.emit('error', new Error('This server is version ' + versionRequired +
', you are using version ' + client.version + ', please specify the correct version in the options.'))
', you are using version ' + client.version + ', please specify the correct version in the options.'))
client.end('differentVersionError')
})
}

View file

@ -34,6 +34,7 @@ function ping (options) {
return new Promise((resolve, reject) => {
client.on('error', function (err) {
clearTimeout(closeTimer)
client.end()
reject(err)
})
client.once('server_info', function (packet) {