Skip to content

Commit

Permalink
handle reset flag
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqiangxu committed Apr 8, 2020
1 parent 0ab267a commit 2c7067c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
13 changes: 10 additions & 3 deletions clientconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type response struct {
func (r *response) GetFrame() (*Frame, error) {
frame := <-r.Frame
if frame == nil {
return nil, ErrConnAlreadyClosed
return nil, ErrStreamClosed
}
return frame, nil
}
Expand All @@ -80,7 +80,7 @@ func (r *response) GetFrameWithContext(ctx context.Context) (*Frame, error) {
select {
case frame := <-r.Frame:
if frame == nil {
return nil, ErrConnAlreadyClosed
return nil, ErrStreamClosed
}
return frame, nil
case <-ctx.Done():
Expand Down Expand Up @@ -329,6 +329,9 @@ var (
ErrNoNewUUID = errors.New("no new uuid available temporary")
// ErrConnAlreadyClosed when try to operate on an already closed conn
ErrConnAlreadyClosed = errors.New("connection already closed")
// ErrStreamClosed used by Response
// reason may be: 1. reset by peer 2. connection closed
ErrStreamClosed = errors.New("stream already closed")
)

func (conn *Connection) nextRequestID() uint64 {
Expand Down Expand Up @@ -521,7 +524,11 @@ func (conn *Connection) readFrames() {
delete(conn.respes, frame.RequestID)
conn.mu.Unlock()

resp.SetResponse(frame)
if frame.Flags.IsRst() {
resp.Close()
} else {
resp.SetResponse(frame)
}

}
}
Expand Down
2 changes: 1 addition & 1 deletion framereader.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ start:
s.ResetByPeer()
}

goto start
return f, nil
}
s, loaded := cs.CreateOrGetStream(dfr.ctx, requestID, flags)
if !loaded {
Expand Down
6 changes: 5 additions & 1 deletion serveconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,11 @@ func (sc *serveconn) readFrames() (err error) {
}
ci.l.Unlock()
if ok {
resp.SetResponse(req)
if req.Flags.IsRst() {
resp.Close()
} else {
resp.SetResponse(req)
}
continue
}
} else {
Expand Down

0 comments on commit 2c7067c

Please sign in to comment.