Goroutine leak hunt (#874)
* close the writers of gin loggers + kill the tomb of httpServer * body close defer
This commit is contained in:
parent
cedfca07c2
commit
01028d0a09
|
@ -119,7 +119,6 @@ func (e *ErrorResponse) Error() string {
|
|||
|
||||
func newResponse(r *http.Response) *Response {
|
||||
response := &Response{Response: r}
|
||||
//response.populatePageValues()
|
||||
return response
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,9 @@ func (c *ApiClient) Do(ctx context.Context, req *http.Request, v interface{}) (*
|
|||
}
|
||||
|
||||
resp, err := c.client.Do(req)
|
||||
|
||||
if resp != nil && resp.Body != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
if err != nil {
|
||||
// If we got an error, and the context has been canceled,
|
||||
// the context's error is probably more useful.
|
||||
|
|
|
@ -3,6 +3,7 @@ package apiserver
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -252,11 +253,6 @@ func (s *APIServer) Run() error {
|
|||
}
|
||||
}()
|
||||
<-s.httpServerTomb.Dying()
|
||||
log.Infof("run: shutting down api server")
|
||||
if err := s.Shutdown(); err != nil {
|
||||
log.Errorf("while shutting down API Server : %s", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
|
@ -278,5 +274,17 @@ func (s *APIServer) Shutdown() error {
|
|||
if err := s.httpServer.Shutdown(context.TODO()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//close io.writer logger given to gin
|
||||
if pipe, ok := gin.DefaultErrorWriter.(*io.PipeWriter); ok {
|
||||
pipe.Close()
|
||||
}
|
||||
if pipe, ok := gin.DefaultWriter.(*io.PipeWriter); ok {
|
||||
pipe.Close()
|
||||
}
|
||||
s.httpServerTomb.Kill(nil)
|
||||
if err := s.httpServerTomb.Wait(); err != nil {
|
||||
return errors.Wrap(err, "while waiting on httpServerTomb")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue