-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
entrust: Close body to avoid some conn leaks
Also ensure that we drain the body before closing to it to reuse the existing connections when possible.
- Loading branch information
Anis Eleuch
committed
Aug 27, 2024
1 parent
c07d23a
commit 6756eec
Showing
10 changed files
with
58 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2024 - MinIO, Inc. All rights reserved. | ||
// Use of this source code is governed by the AGPLv3 | ||
// license that can be found in the LICENSE file. | ||
|
||
package http | ||
|
||
import ( | ||
"io" | ||
) | ||
|
||
// DrainBody close non nil response with any response Body. | ||
// convenient wrapper to drain any remaining data on response body. | ||
// | ||
// Subsequently this allows golang http RoundTripper | ||
// to reuse the same connection for future requests. | ||
func DrainBody(respBody io.ReadCloser) { | ||
// Callers should close resp.Body when done reading from it. | ||
// If resp.Body is not closed, the Client's underlying RoundTripper | ||
// (typically Transport) may not be able to reuse a persistent TCP | ||
// connection to the server for a subsequent "keep-alive" request. | ||
if respBody != nil { | ||
// Drain any remaining Body and then close the connection. | ||
// Without this closing connection would disallow re-using | ||
// the same connection for future uses. | ||
// - http://stackoverflow.com/a/17961593/4465767 | ||
io.Copy(io.Discard, respBody) | ||
respBody.Close() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters