mirror of
https://github.com/c0re100/gotdlib.git
synced 2026-02-22 04:30:17 +01:00
fix: time.After will cause memory leak
This commit is contained in:
parent
98e8cb003f
commit
278b1ae10d
1 changed files with 6 additions and 2 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -123,17 +124,20 @@ func (client *Client) Send(req Request) (*Response, error) {
|
|||
client.catchersStore.Store(req.Extra, catcher)
|
||||
|
||||
defer func() {
|
||||
close(catcher)
|
||||
client.catchersStore.Delete(req.Extra)
|
||||
close(catcher)
|
||||
}()
|
||||
|
||||
client.jsonClient.Send(req)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), client.catchTimeout)
|
||||
defer cancel()
|
||||
|
||||
select {
|
||||
case response := <-catcher:
|
||||
return response, nil
|
||||
|
||||
case <-time.After(client.catchTimeout):
|
||||
case <-ctx.Done():
|
||||
return nil, errors.New("response catching timeout")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue