<#7046 fix: close HTTP response bodies and file ha...
# flyte-github
a
#7046 fix: close HTTP response bodies and file handles to prevent resource leaks Pull request opened by themavik Summary Several resource leaks found across the codebase where HTTP response bodies and file handles are not properly closed. These can cause connection pool exhaustion, file descriptor leaks, and memory leaks in long-running processes. Changes 1.
flyteadmin/auth/authzserver/metadata_provider.go
• Added
defer response.Body.Close()
after successful HTTP response in
GetOAuth2Metadata
• Added
response.Body.Close()
before retry when receiving 4xx/5xx status codes in
sendAndRetryHTTPRequest
— without this, each retry iteration leaks the previous response body 2.
flytectl/cmd/register/register_util.go
• Added
defer res.Body.Close()
in
DirectUpload
— the response body was never closed on either success or error paths 3.
flytectl/pkg/filesystemutils/file_system_utils.go
• Added
outFile.Close()
before returning on non-EOF
io.CopyN
error during tar extraction — the file handle was leaked when extraction failed mid-stream 4.
flytestdlib/config/viper/collection.go
• Added
reader.Close()
after
MergeConfig
in
GetConfig
— the config file reader was opened but never closed Testing • All changes are mechanical resource cleanup additions • No behavioral changes — only ensures proper cleanup of OS resources • Existing tests continue to pass as the changes only affect cleanup paths flyteorg/flyte