Skip to content

Commit 9313d13

Browse files
committed
close the connection at shutdown + fix race condition
1 parent 686ea4d commit 9313d13

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

dbos/conductor.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
const (
1919
_PING_INTERVAL = 20 * time.Second
20-
_PING_TIMEOUT = 30 * time.Second // Should be > server's executorPingWait (25s)
20+
_PING_TIMEOUT = 30 * time.Second // Should be slightly greater than server's executorPingWait (25s)
2121
_INITIAL_RECONNECT_WAIT = 1 * time.Second
2222
_MAX_RECONNECT_WAIT = 30 * time.Second
2323
_HANDSHAKE_TIMEOUT = 10 * time.Second
@@ -118,6 +118,8 @@ func (c *Conductor) Shutdown(timeout time.Duration) {
118118
c.pingCancel()
119119
}
120120

121+
c.closeConn()
122+
121123
done := make(chan struct{})
122124
go func() {
123125
c.wg.Wait()
@@ -141,6 +143,10 @@ func (c *Conductor) closeConn() {
141143
c.pingCancel = nil
142144
}
143145

146+
// Acquire write mutex to ensure no concurrent writes during close
147+
c.writeMu.Lock()
148+
defer c.writeMu.Unlock()
149+
144150
if c.conn != nil {
145151
if err := c.conn.SetWriteDeadline(time.Now().Add(5 * time.Second)); err != nil {
146152
c.logger.Warn("Failed to set write deadline", "error", err)

0 commit comments

Comments
 (0)