Selaa lähdekoodia

Fix race between sender and receiver.

Gary Burd 13 vuotta sitten
vanhempi
commit
b85fd5bc22
1 muutettua tiedostoa jossa 3 lisäystä ja 3 poistoa
  1. 3 3
      redis/conn.go

+ 3 - 3
redis/conn.go

@@ -228,15 +228,15 @@ func (c *conn) readReply() (interface{}, error) {
 }
 }
 
 
 func (c *conn) Send(cmd string, args ...interface{}) error {
 func (c *conn) Send(cmd string, args ...interface{}) error {
+	c.mu.Lock()
+	c.pending += 1
+	c.mu.Unlock()
 	if c.writeTimeout != 0 {
 	if c.writeTimeout != 0 {
 		c.conn.SetWriteDeadline(time.Now().Add(c.writeTimeout))
 		c.conn.SetWriteDeadline(time.Now().Add(c.writeTimeout))
 	}
 	}
 	if err := c.writeCommand(cmd, args); err != nil {
 	if err := c.writeCommand(cmd, args); err != nil {
 		return c.fatal(err)
 		return c.fatal(err)
 	}
 	}
-	c.mu.Lock()
-	c.pending += 1
-	c.mu.Unlock()
 	return nil
 	return nil
 }
 }