Fix deadlock(s)

This commit is contained in:
nak 2026-03-20 08:19:26 +00:00
parent 087534ce23
commit 081ba5da4e
3 changed files with 18 additions and 27 deletions

View file

@ -2,7 +2,7 @@
set -e set -e
echo "Pulling latest..." echo "Pulling latest..."
git pull #git pull
echo "Building..." echo "Building..."
go build -o overte-api . go build -o overte-api .

32
hub.go
View file

@ -64,22 +64,22 @@ func (h *Hub) count() int {
// SendToUser sends a message to the first client identified as username. // SendToUser sends a message to the first client identified as username.
func (h *Hub) SendToUser(username string, msg interface{}) { func (h *Hub) SendToUser(username string, msg interface{}) {
data, err := json.Marshal(msg) data, err := json.Marshal(msg)
if err != nil { if err != nil {
return return
} }
h.mu.RLock() h.mu.RLock()
defer h.mu.RUnlock() defer h.mu.RUnlock()
for c := range h.clients { for c := range h.clients {
if c.username == username { if c.username == username {
select { select {
case c.send <- data: case c.send <- data:
default: default:
log.Printf("[WS] dropped private message to %s", username) log.Printf("[WS] dropped private message to %s (channel full)", username)
} }
return // no return — send to all matching clients
} }
} }
} }
func (h *Hub) Broadcast(msg interface{}, sender *Client) { func (h *Hub) Broadcast(msg interface{}, sender *Client) {

View file

@ -415,25 +415,21 @@ func (t *Table) Reveal(username string) {
func (t *Table) advance() { func (t *Table) advance() {
t.mu.Lock() t.mu.Lock()
defer t.mu.Unlock()
// Check if only one player remains
if t.countActivePlayers() == 1 { if t.countActivePlayers() == 1 {
t.mu.Unlock()
t.awardPot() t.awardPot()
return return
} }
// Check if betting is complete for this street
if !t.bettingComplete() { if !t.bettingComplete() {
t.Hand.ActionOn = t.nextActiveSeat(t.Hand.ActionOn) t.Hand.ActionOn = t.nextActiveSeat(t.Hand.ActionOn)
t.mu.Unlock() t.mu.Unlock()
t.broadcastState() t.broadcastState()
t.startTurnTimer() t.startTurnTimer()
t.mu.Lock()
return return
} }
// Advance to next street
switch t.Hand.Phase { switch t.Hand.Phase {
case PhasePreflop: case PhasePreflop:
var cards []string var cards []string
@ -454,24 +450,19 @@ func (t *Table) advance() {
t.Hand.Phase = PhaseShowdown t.Hand.Phase = PhaseShowdown
t.mu.Unlock() t.mu.Unlock()
t.doShowdown() t.doShowdown()
t.mu.Lock()
return return
} }
// Reset bets for new street
for _, s := range t.Seats { for _, s := range t.Seats {
s.Bet = 0 s.Bet = 0
} }
t.acted = make(map[string]bool) t.acted = make(map[string]bool)
t.Hand.LastRaise = 0 t.Hand.LastRaise = 0
t.Hand.MinRaise = t.Config.BigBlind t.Hand.MinRaise = t.Config.BigBlind
// Action starts left of dealer post-flop
t.Hand.ActionOn = t.nextActiveSeat(t.Hand.DealerSeat) t.Hand.ActionOn = t.nextActiveSeat(t.Hand.DealerSeat)
t.mu.Unlock() t.mu.Unlock()
t.broadcastState() t.broadcastState()
t.startTurnTimer() t.startTurnTimer()
t.mu.Lock()
} }
func (t *Table) doShowdown() { func (t *Table) doShowdown() {