소스 검색

dont release the stream if we get a timeout

If we get a timeout it means that a response can still come in
on the outstanding stream, if another request uses this stream
then it will get a reponse for the previous request.
Chris Bannister 10 년 전
부모
커밋
676814747f
1개의 변경된 파일6개의 추가작업 그리고 1개의 파일을 삭제
  1. 6 1
      conn.go

+ 6 - 1
conn.go

@@ -337,6 +337,7 @@ func (c *Conn) recv() error {
 	select {
 	case call.resp <- err:
 	default:
+		c.releaseStream(head.stream)
 		// in case the caller timedout
 	}
 
@@ -365,7 +366,6 @@ func (c *Conn) handleTimeout() {
 func (c *Conn) exec(req frameWriter, tracer Tracer) (frame, error) {
 	// TODO: move tracer onto conn
 	stream := <-c.uniq
-	defer c.releaseStream(stream)
 
 	call := &c.calls[stream]
 	// resp is basically a waiting semaphore protecting the framer
@@ -383,6 +383,11 @@ func (c *Conn) exec(req frameWriter, tracer Tracer) (frame, error) {
 
 	err = <-call.resp
 
+	// dont release the stream if detect a timeout as another request can reuse
+	// that stream and get a response for the old request, which we have no
+	// easy way of detecting.
+	defer c.releaseStream(stream)
+
 	if err != nil {
 		return nil, err
 	}