Merge pull request #640 from iamqizhao/master
Fix a couple of misuse of ctx introduced recently
This commit is contained in:
transport
@ -233,8 +233,10 @@ func (t *http2Client) NewStream(ctx context.Context, callHdr *CallHdr) (_ *Strea
|
|||||||
if dl, ok := ctx.Deadline(); ok {
|
if dl, ok := ctx.Deadline(); ok {
|
||||||
timeout = dl.Sub(time.Now())
|
timeout = dl.Sub(time.Now())
|
||||||
}
|
}
|
||||||
if err := ctx.Err(); err != nil {
|
select {
|
||||||
return nil, ContextErr(err)
|
case <-ctx.Done():
|
||||||
|
return nil, ContextErr(ctx.Err())
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
pr := &peer.Peer{
|
pr := &peer.Peer{
|
||||||
Addr: t.conn.RemoteAddr(),
|
Addr: t.conn.RemoteAddr(),
|
||||||
@ -516,13 +518,15 @@ func (t *http2Client) Write(s *Stream, data []byte, opts *Options) error {
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if s.ctx.Err() != nil {
|
select {
|
||||||
|
case <-s.ctx.Done():
|
||||||
t.sendQuotaPool.add(len(p))
|
t.sendQuotaPool.add(len(p))
|
||||||
if t.framer.adjustNumWriters(-1) == 0 {
|
if t.framer.adjustNumWriters(-1) == 0 {
|
||||||
t.controlBuf.put(&flushIO{})
|
t.controlBuf.put(&flushIO{})
|
||||||
}
|
}
|
||||||
t.writableChan <- 0
|
t.writableChan <- 0
|
||||||
return ContextErr(s.ctx.Err())
|
return ContextErr(s.ctx.Err())
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
if r.Len() == 0 && t.framer.adjustNumWriters(0) == 1 {
|
if r.Len() == 0 && t.framer.adjustNumWriters(0) == 1 {
|
||||||
// Do a force flush iff this is last frame for the entire gRPC message
|
// Do a force flush iff this is last frame for the entire gRPC message
|
||||||
|
@ -600,13 +600,15 @@ func (t *http2Server) Write(s *Stream, data []byte, opts *Options) error {
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if s.ctx.Err() != nil {
|
select {
|
||||||
|
case <-s.ctx.Done():
|
||||||
t.sendQuotaPool.add(ps)
|
t.sendQuotaPool.add(ps)
|
||||||
if t.framer.adjustNumWriters(-1) == 0 {
|
if t.framer.adjustNumWriters(-1) == 0 {
|
||||||
t.controlBuf.put(&flushIO{})
|
t.controlBuf.put(&flushIO{})
|
||||||
}
|
}
|
||||||
t.writableChan <- 0
|
t.writableChan <- 0
|
||||||
return ContextErr(s.ctx.Err())
|
return ContextErr(s.ctx.Err())
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
var forceFlush bool
|
var forceFlush bool
|
||||||
if r.Len() == 0 && t.framer.adjustNumWriters(0) == 1 && !opts.Last {
|
if r.Len() == 0 && t.framer.adjustNumWriters(0) == 1 && !opts.Last {
|
||||||
|
Reference in New Issue
Block a user