MCPcopy
hub / github.com/jackc/pgx / Release

Method Release

pgxpool/conn.go:19–67  ·  view source on GitHub ↗

Release returns c to the pool it was acquired from. Once Release has been called, other methods must not be called. However, it is safe to call Release multiple times. Subsequent calls after the first will be ignored.

()

Source from the content-addressed store, hash-verified

17// Release returns c to the pool it was acquired from. Once Release has been called, other methods must not be called.
18// However, it is safe to call Release multiple times. Subsequent calls after the first will be ignored.
19func (c *Conn) Release() {
20 if c.res == nil {
21 return
22 }
23
24 conn := c.Conn()
25 res := c.res
26 c.res = nil
27
28 if c.p.releaseTracer != nil {
29 c.p.releaseTracer.TraceRelease(c.p, TraceReleaseData{Conn: conn})
30 }
31
32 if conn.IsClosed() || conn.PgConn().IsBusy() || conn.PgConn().TxStatus() != 'I' {
33 res.Destroy()
34 // Signal to the health check to run since we just destroyed a connections
35 // and we might be below minConns now
36 c.p.triggerHealthCheck()
37 return
38 }
39
40 // If the pool is consistently being used, we might never get to check the
41 // lifetime of a connection since we only check idle connections in checkConnsHealth
42 // so we also check the lifetime here and force a health check
43 if c.p.isExpired(res) {
44 c.p.lifetimeDestroyCount.Add(1)
45 res.Destroy()
46 // Signal to the health check to run since we just destroyed a connections
47 // and we might be below minConns now
48 c.p.triggerHealthCheck()
49 return
50 }
51
52 if c.p.afterRelease == nil {
53 res.Release()
54 return
55 }
56
57 go func() {
58 if c.p.afterRelease(conn) {
59 res.Release()
60 } else {
61 res.Destroy()
62 // Signal to the health check to run since we just destroyed a connections
63 // and we might be below minConns now
64 c.p.triggerHealthCheck()
65 }
66 }()
67}
68
69// Hijack assumes ownership of the connection from the pool. Caller is responsible for closing the connection. Hijack
70// will panic if called on an already released or hijacked connection.

Callers 15

ConnectMethod · 0.95
TestLogAcquireFunction · 0.80
TestLogReleaseFunction · 0.80
TestTraceAcquireFunction · 0.80
TestTraceReleaseFunction · 0.80
TestConnExecFunction · 0.80
TestConnQueryFunction · 0.80
TestConnQueryRowFunction · 0.80
TestConnSendBatchFunction · 0.80
TestConnCopyFromFunction · 0.80
CloseMethod · 0.80
ScanMethod · 0.80

Calls 8

ConnMethod · 0.95
IsBusyMethod · 0.80
PgConnMethod · 0.80
TxStatusMethod · 0.80
triggerHealthCheckMethod · 0.80
isExpiredMethod · 0.80
TraceReleaseMethod · 0.65
IsClosedMethod · 0.45

Tested by 15

TestLogAcquireFunction · 0.64
TestLogReleaseFunction · 0.64
TestTraceAcquireFunction · 0.64
TestTraceReleaseFunction · 0.64
TestConnExecFunction · 0.64
TestConnQueryFunction · 0.64
TestConnQueryRowFunction · 0.64
TestConnSendBatchFunction · 0.64
TestConnCopyFromFunction · 0.64