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