| 667 | } |
| 668 | |
| 669 | closeUnsafe(): void { |
| 670 | this.closed = true |
| 671 | const socket = this.session.socket |
| 672 | let destroySocket = true |
| 673 | if (this.deadWith === undefined && socket.writable) { |
| 674 | try { |
| 675 | // Once Terminate and our FIN have reached the kernel there is nothing |
| 676 | // left to read, so the descriptor is released without waiting for the |
| 677 | // peer's FIN, which a half-open proxy may never send. |
| 678 | const timeout = setTimeout(() => socket.destroy(), terminateTimeoutMillis) |
| 679 | timeout.unref() |
| 680 | socket.once("finish", () => socket.destroy()) |
| 681 | socket.once("close", () => clearTimeout(timeout)) |
| 682 | socket.end(PgProtocol.encodeTerminate()) |
| 683 | destroySocket = false |
| 684 | } catch { |
| 685 | // Fall back to the fatal path's immediate destroy below. |
| 686 | } |
| 687 | } |
| 688 | this.fatal( |
| 689 | new SqlError({ |
| 690 | reason: new ConnectionError({ |
| 691 | cause: new Error("Connection is closed"), |
| 692 | message: "PgConnection: Connection is closed", |
| 693 | operation: "query" |
| 694 | }) |
| 695 | }), |
| 696 | destroySocket |
| 697 | ) |
| 698 | socket.off("data", this.onData) |
| 699 | socket.off("error", this.onSocketError) |
| 700 | socket.off("close", this.onSocketClose) |
| 701 | this.retireHooks.clear() |
| 702 | } |
| 703 | |
| 704 | /** Plans one execution. `cache` is `undefined` to force the unnamed path. */ |
| 705 | readonly encodeQuery = ( |