good morning!!!!

Skip to content
Snippets Groups Projects
Commit a83b6a66 authored by Garet Halliday's avatar Garet Halliday
Browse files

i hate races

parent fa64fbdf
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@ general:
admin_password: postgres
pools:
simple_db:
pool_mode: session
pool_mode: transaction
default_role: primary
query_parser_enabled: true
primary_reads_enabled: true
......
......@@ -153,20 +153,25 @@ func (g *Gatling) ListenAndServe(ctx context.Context) error {
}
go func() {
for {
var c net.Conn
c, err = ln.Accept()
if err != nil {
log.Println("failed to accept connection:", err)
}
errch := make(chan error)
go func() {
c, err := ln.Accept()
if err != nil {
errch <- err
}
close(errch)
err = g.handleConnection(ctx, c)
if err != nil {
if err != io.EOF {
log.Println("disconnected:", err)
}
return
}
}()
err = <-errch
if err != nil {
log.Println("failed to accept connection:", err)
}
}
}()
return nil
......
......@@ -6,6 +6,7 @@ import (
"gfx.cafe/gfx/pggat/lib/gat"
"gfx.cafe/gfx/pggat/lib/gat/protocol"
"runtime"
"sync"
"sync/atomic"
)
......@@ -19,6 +20,8 @@ type Pool struct {
assigned map[gat.ClientID]gat.Connection
servers chan gat.Connection
mu sync.Mutex
}
func New(database gat.Database, dialer gat.Dialer, conf *config.Pool, user *config.User) *Pool {
......@@ -52,6 +55,8 @@ func (p *Pool) returnConnection(c gat.Connection) {
}
func (p *Pool) getOrAssign(client gat.Client) gat.Connection {
p.mu.Lock()
defer p.mu.Unlock()
cid := client.GetId()
c, ok := p.assigned[cid]
if !ok {
......@@ -71,6 +76,8 @@ func (p *Pool) EnsureConfig(c *config.Pool) {
}
func (p *Pool) OnDisconnect(client gat.Client) {
p.mu.Lock()
defer p.mu.Unlock()
cid := client.GetId()
c, ok := p.assigned[cid]
if !ok {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment