diff --git a/go.mod b/go.mod index 57cf754..5ac1407 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.21 require ( github.com/jackc/pgx/v4 v4.18.1 github.com/logrusorgru/aurora/v3 v3.0.0 + github.com/sasha-s/go-deadlock v0.3.1 golang.org/x/net v0.17.0 ) @@ -17,6 +18,7 @@ require ( github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/pgtype v1.14.0 // indirect github.com/jackc/puddle v1.3.0 // indirect + github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect golang.org/x/crypto v0.14.0 // indirect golang.org/x/text v0.13.0 // indirect ) diff --git a/go.sum b/go.sum index 5d74c0c..87a5472 100644 --- a/go.sum +++ b/go.sum @@ -82,6 +82,8 @@ github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ= +github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -90,6 +92,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= +github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0= +github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= diff --git a/gpcm/main.go b/gpcm/main.go index 640be7a..95788cb 100644 --- a/gpcm/main.go +++ b/gpcm/main.go @@ -7,7 +7,6 @@ import ( "fmt" "io" "net" - "sync" "wwfc/common" "wwfc/database" "wwfc/logging" @@ -15,6 +14,7 @@ import ( "github.com/jackc/pgx/v4/pgxpool" "github.com/logrusorgru/aurora/v3" + "github.com/sasha-s/go-deadlock" ) type GameSpySession struct { @@ -45,7 +45,7 @@ var ( pool *pgxpool.Pool // I would use a sync.Map instead of the map mutex combo, but this performs better. sessions = map[uint32]*GameSpySession{} - mutex = sync.RWMutex{} + mutex = deadlock.Mutex{} ) func StartServer() { diff --git a/qr2/logins.go b/qr2/logins.go index 3d1f2ca..bf26f22 100644 --- a/qr2/logins.go +++ b/qr2/logins.go @@ -49,7 +49,9 @@ func Logout(profileID uint32) { // Delete login's session if login, exists := logins[profileID]; exists { if login.Session != nil { + mutex.Unlock() removeSession(makeLookupAddr(login.Session.Addr.String())) + mutex.Lock() } } diff --git a/qr2/session.go b/qr2/session.go index 26495cc..5ab74fc 100644 --- a/qr2/session.go +++ b/qr2/session.go @@ -5,12 +5,12 @@ import ( "net" "strconv" "strings" - "sync" "time" "wwfc/common" "wwfc/logging" "github.com/logrusorgru/aurora/v3" + "github.com/sasha-s/go-deadlock" ) const ( @@ -38,7 +38,7 @@ type Session struct { var ( sessions = map[uint64]*Session{} sessionBySearchID = map[uint64]*Session{} - mutex = sync.RWMutex{} + mutex = deadlock.Mutex{} ) // Remove a session.