[#393] rpc/grpc: Use NewTimer instead of time.After

From the docs of `time.After`:
```
The underlying Timer is not recovered by the garbage collector until the timer fires.
```
We have 1 minute default timeout, which is pretty long given that most
of the time we exchange small messages.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-04-11 13:47:29 +03:00 committed by LeL
parent 23702bc51a
commit e8e09f0d00

View file

@ -57,10 +57,13 @@ func (w *streamWrapper) withTimeout(closure func() error) error {
close(ch) close(ch)
}() }()
tt := time.NewTimer(w.timeout)
select { select {
case err := <-ch: case err := <-ch:
tt.Stop()
return err return err
case <-time.After(w.timeout): case <-tt.C:
w.cancel() w.cancel()
return context.DeadlineExceeded return context.DeadlineExceeded
} }