| 436 | } |
| 437 | |
| 438 | async function closed(hadError) { |
| 439 | incoming = Buffer.alloc(0) |
| 440 | remaining = 0 |
| 441 | incomings = null |
| 442 | clearImmediate(nextWriteTimer) |
| 443 | socket.removeListener('data', data) |
| 444 | socket.removeListener('connect', connected) |
| 445 | idleTimer.cancel() |
| 446 | lifeTimer.cancel() |
| 447 | connectTimer.cancel() |
| 448 | |
| 449 | socket.removeAllListeners() |
| 450 | socket = null |
| 451 | |
| 452 | if (initial) |
| 453 | return reconnect() |
| 454 | |
| 455 | !hadError && (query || sent.length) && error(Errors.connection('CONNECTION_CLOSED', options, socket)) |
| 456 | closedTime = performance.now() |
| 457 | hadError && options.shared.retries++ |
| 458 | delay = (typeof backoff === 'function' ? backoff(options.shared.retries) : backoff) * 1000 |
| 459 | onclose(connection, Errors.connection('CONNECTION_CLOSED', options, socket)) |
| 460 | } |
| 461 | |
| 462 | /* Handlers */ |
| 463 | function handle(xs, x = xs[0]) { |