diff --git a/lib/fed/conn.go b/lib/fed/conn.go index 547981adff48d7d564ff4b653fd9b05504b75b6d..f01d71c86bde6b2bdc22df91dcd794aedda01558 100644 --- a/lib/fed/conn.go +++ b/lib/fed/conn.go @@ -18,7 +18,9 @@ type Conn struct { NetConn net.Conn Middleware []Middleware - SSL bool + + SSL bool + Ready bool User string Database string diff --git a/lib/gat/handlers/pgbouncer/module.go b/lib/gat/handlers/pgbouncer/module.go index 0dd0baafc43eef66cd60f726a7d85a8e60fcc24d..30deb767c54710d265b82c5e0b9b270db97000a7 100644 --- a/lib/gat/handlers/pgbouncer/module.go +++ b/lib/gat/handlers/pgbouncer/module.go @@ -120,7 +120,7 @@ func (T *Module) getPassword(user, database string) (string, bool) { }) b.Queue(func() error { - err := authPool.ServeBot(outward) + err := authPool.Serve(outward) if err != nil && !errors.Is(err, io.EOF) { return err } diff --git a/lib/gat/pool.go b/lib/gat/pool.go index f0dc34147ada3d783d651e0be8492e88b23b5484..e3f96693e34a5bd3c83e2cbe073cd86ce154769a 100644 --- a/lib/gat/pool.go +++ b/lib/gat/pool.go @@ -1,5 +1,7 @@ package gat -import "gfx.cafe/gfx/pggat/lib/gat/pool" +import ( + "gfx.cafe/gfx/pggat/lib/gat/pool" +) type Pool = pool.Pool diff --git a/lib/gat/pool/pool.go b/lib/gat/pool/pool.go index 258ced2197dc5d878d51b13bbd5770168ed4c767..8d79cc1ac528897631f7ee402fc6464efb9cc433 100644 --- a/lib/gat/pool/pool.go +++ b/lib/gat/pool/pool.go @@ -289,27 +289,10 @@ func (T *Pool) Serve( conn, ) - return T.serve(client, false) + return T.serve(client) } -// ServeBot is for clients that don't need initial parameters, cancelling queries, and are ready now. Use Serve for -// real clients -func (T *Pool) ServeBot( - conn *fed.Conn, -) error { - defer func() { - _ = conn.Close() - }() - - client := newClient( - T.config, - conn, - ) - - return T.serve(client, true) -} - -func (T *Pool) serve(client *pooledClient, initialized bool) error { +func (T *Pool) serve(client *pooledClient) error { T.addClient(client) defer T.removeClient(client) @@ -328,7 +311,7 @@ func (T *Pool) serve(client *pooledClient, initialized bool) error { } }() - if !initialized { + if !client.GetConn().Ready { server = T.acquireServer(client) if server == nil { return ErrClosed @@ -347,6 +330,8 @@ func (T *Pool) serve(client *pooledClient, initialized bool) error { if err != nil { return err } + + client.GetConn().Ready = true } for { diff --git a/lib/gsql/pair.go b/lib/gsql/pair.go index 8355d5d13bb0e2726b516efe399dab2ff47e528b..e6ceb79c563cc62fec49f976cb31b6ae70679526 100644 --- a/lib/gsql/pair.go +++ b/lib/gsql/pair.go @@ -8,7 +8,9 @@ import ( func NewPair() (*fed.Conn, *fed.Conn) { conn := new(mio.Conn) inward := fed.NewConn(mio.InwardConn{Conn: conn}) + inward.Ready = true outward := fed.NewConn(mio.OutwardConn{Conn: conn}) + outward.Ready = true return inward, outward }