fixing two goroutine leaks and one panic

This commit is contained in:
Linhai Song 2021-12-15 22:38:25 -05:00
parent 29292aa7bd
commit 0098dbf350
2 changed files with 7 additions and 1 deletions

View File

@ -607,7 +607,9 @@ func (c *simpleHTTPClient) Do(ctx context.Context, act httpAction) (*http.Respon
select { select {
case <-ctx.Done(): case <-ctx.Done():
resp.Body.Close() if resp != nil {
resp.Body.Close()
}
<-done <-done
return nil, nil, ctx.Err() return nil, nil, ctx.Err()
case <-done: case <-done:

View File

@ -35,6 +35,8 @@ func TestWatch(t *testing.T) {
s := newWatchableStore(zap.NewExample(), b, &lease.FakeLessor{}, StoreConfig{}) s := newWatchableStore(zap.NewExample(), b, &lease.FakeLessor{}, StoreConfig{})
defer func() { defer func() {
b.Close()
s.Close()
s.store.Close() s.store.Close()
os.Remove(tmpPath) os.Remove(tmpPath)
}() }()
@ -536,6 +538,8 @@ func TestWatchVictims(t *testing.T) {
s := newWatchableStore(zap.NewExample(), b, &lease.FakeLessor{}, StoreConfig{}) s := newWatchableStore(zap.NewExample(), b, &lease.FakeLessor{}, StoreConfig{})
defer func() { defer func() {
b.Close()
s.Close()
s.store.Close() s.store.Close()
os.Remove(tmpPath) os.Remove(tmpPath)
chanBufLen, maxWatchersPerSync = oldChanBufLen, oldMaxWatchersPerSync chanBufLen, maxWatchersPerSync = oldChanBufLen, oldMaxWatchersPerSync