Skip to content

Commit 0f075d6

Browse files
authored
fix: connection state race (#311)
1 parent 83bcc41 commit 0f075d6

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

core/client.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,13 @@ func (c *Client) setState(state ConnState) {
267267
c.mu.Unlock()
268268
}
269269

270+
// getState get connection state
271+
func (c *Client) getState() ConnState {
272+
c.mu.Lock()
273+
defer c.mu.Unlock()
274+
return c.state
275+
}
276+
270277
// update connection local addr
271278
func (c *Client) setLocalAddr(addr string) {
272279
c.mu.Lock()
@@ -285,7 +292,7 @@ func (c *Client) reconnect(ctx context.Context, addr string) {
285292
t := time.NewTicker(1 * time.Second)
286293
defer t.Stop()
287294
for range t.C {
288-
if c.state == ConnStateDisconnected {
295+
if c.getState() == ConnStateDisconnected {
289296
c.logger.Printf("%s[%s](%s) is reconnecting to YoMo-Zipper %s...\n", ClientLogPrefix, c.name, c.localAddr, addr)
290297
err := c.connect(ctx, addr)
291298
if err != nil {

0 commit comments

Comments
 (0)