fix broken pipe error
This commit is contained in:
parent
850f8bafdf
commit
f80f0eb38e
@ -214,9 +214,7 @@ func (s *service) call(ctx context.Context, router *router, sending *sync.Mutex,
|
||||
// declare a local error to see if we errored out already
|
||||
// keep track of the type, to make sure we return
|
||||
// the same one consistently
|
||||
var lastError error
|
||||
|
||||
stream := &rpcStream{
|
||||
rawStream := &rpcStream{
|
||||
context: ctx,
|
||||
codec: cc.(codec.Codec),
|
||||
request: r,
|
||||
@ -229,9 +227,8 @@ func (s *service) call(ctx context.Context, router *router, sending *sync.Mutex,
|
||||
if err := returnValues[0].Interface(); err != nil {
|
||||
// the function returned an error, we use that
|
||||
return err.(error)
|
||||
} else if lastError != nil {
|
||||
// we had an error inside sendReply, we use that
|
||||
return lastError
|
||||
} else if serr := rawStream.Error(); serr == io.EOF || serr == io.ErrUnexpectedEOF {
|
||||
return nil
|
||||
} else {
|
||||
// no error, we send the special EOS error
|
||||
return lastStreamResponseError
|
||||
@ -242,14 +239,7 @@ func (s *service) call(ctx context.Context, router *router, sending *sync.Mutex,
|
||||
r.stream = true
|
||||
|
||||
// execute handler
|
||||
if err := fn(ctx, r, stream); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// this is the last packet, we don't do anything with
|
||||
// the error here (well sendStreamResponse will log it
|
||||
// already)
|
||||
return router.sendResponse(sending, req, nil, cc, true)
|
||||
return fn(ctx, r, rawStream)
|
||||
}
|
||||
|
||||
func (m *methodType) prepareContext(ctx context.Context) reflect.Value {
|
||||
|
@ -38,7 +38,11 @@ func (r *rpcStream) Send(msg interface{}) error {
|
||||
Type: codec.Response,
|
||||
}
|
||||
|
||||
return r.codec.Write(&resp, msg)
|
||||
if err := r.codec.Write(&resp, msg); err != nil {
|
||||
r.err = err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *rpcStream) Recv(msg interface{}) error {
|
||||
@ -51,12 +55,18 @@ func (r *rpcStream) Recv(msg interface{}) error {
|
||||
if err := r.codec.ReadHeader(req, req.Type); err != nil {
|
||||
// discard body
|
||||
r.codec.ReadBody(nil)
|
||||
r.err = err
|
||||
return err
|
||||
}
|
||||
|
||||
// we need to stay up to date with sequence numbers
|
||||
r.id = req.Id
|
||||
return r.codec.ReadBody(msg)
|
||||
if err := r.codec.ReadBody(msg); err != nil {
|
||||
r.err = err
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *rpcStream) Error() error {
|
||||
|
Loading…
Reference in New Issue
Block a user