Skip to content

Commit

Permalink
perf: optimize server-side handling of timeout control
Browse files Browse the repository at this point in the history
  • Loading branch information
lbbniu committed Jan 8, 2024
1 parent 9319267 commit a7f73e0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tars/transport/tarsserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ func (ts *TarsServer) invoke(ctx context.Context, pkg []byte) []byte {
if cfg.HandleTimeout == 0 {
rsp = ts.protocol.Invoke(ctx, pkg)
} else {
invokeDone, cancelFunc := context.WithTimeout(context.Background(), cfg.HandleTimeout)
invokeCtx, cancelFunc := context.WithTimeout(ctx, cfg.HandleTimeout)
go func() {
rsp = ts.protocol.Invoke(ctx, pkg)
rsp = ts.protocol.Invoke(invokeCtx, pkg)
cancelFunc()
}()
<-invokeDone.Done()
<-invokeCtx.Done()
if len(rsp) == 0 { // The rsp must be none-empty
rsp = ts.protocol.InvokeTimeout(pkg)
}
Expand Down

0 comments on commit a7f73e0

Please sign in to comment.