소스 검색

Fix a problem where an error in onItem could result in a bad connection being reused

If an error occurs inside the fn() that onItem calls it would have not been spotted by
condRelease() and that could result in a bad connection being placed back in the
pool of free connections. Under load the package was experiencing this problem manifested
in the following fashion:

  1. A connection gets an i/o timeout during a call to onItem()

  2. The error returned by the function called by onItem() is placed in a new
     err value (because of the :=) but the condRelease() has been set up with
     &err from a previous declaration of err. Therefore err is nil.

  3. condRelease() places the connection back in the free list.

  4. The connection is reused at some point and there's data waiting to be read
     from the previous memcache command that got the i/o timeout. This results
     in (typically) an error from the Sscanf line at line 405 because that line
     ends up trying to parse part of the response that was not previously read
     because of the i/o timeout.

This fix prevents this from happening. If an error occurs the connection will not be
reused.
John Graham-Cumming 13 년 전
부모
커밋
1c05224a56
1개의 변경된 파일1개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      memcache/memcache.go

+ 1 - 1
memcache/memcache.go

@@ -289,7 +289,7 @@ func (c *Client) onItem(item *Item, fn func(*Client, *bufio.ReadWriter, *Item) e
 		return err
 		return err
 	}
 	}
 	defer cn.condRelease(&err)
 	defer cn.condRelease(&err)
-	if err := fn(c, cn.rw, item); err != nil {
+	if err = fn(c, cn.rw, item); err != nil {
 		return err
 		return err
 	}
 	}
 	return nil
 	return nil