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