MCPcopy Create free account
hub / github.com/Effect-TS/effect / closeUnsafe

Method closeUnsafe

packages/sql/pg/src/PgConnection.ts:669–702  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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 = (

Callers

nothing calls this directly

Calls 6

fatalMethod · 0.95
onceMethod · 0.80
unrefMethod · 0.65
endMethod · 0.65
clearMethod · 0.65
destroyMethod · 0.45

Tested by

no test coverage detected