Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leaking file descriptors from config.Load #803

Open
ear7h opened this issue Aug 13, 2021 · 0 comments
Open

Leaking file descriptors from config.Load #803

ear7h opened this issue Aug 13, 2021 · 0 comments

Comments

@ear7h
Copy link
Contributor

ear7h commented Aug 13, 2021

I think the following function is leaking file descriptors by not calling Close on the http request or opened file:

tegola/config/config.go

Lines 285 to 320 in ac82d5f

func Load(location string) (conf Config, err error) {
var reader io.Reader
// check for http prefix
if strings.HasPrefix(location, "http") {
log.Infof("loading remote config (%v)", location)
// setup http client with a timeout
var httpClient = &http.Client{
Timeout: time.Second * 10,
}
// make the http request
res, err := httpClient.Get(location)
if err != nil {
return conf, fmt.Errorf("error fetching remote config file (%v): %v ", location, err)
}
// set the reader to the response body
reader = res.Body
} else {
log.Infof("loading local config (%v)", location)
// check the conf file exists
if _, err := os.Stat(location); os.IsNotExist(err) {
return conf, fmt.Errorf("config file at location (%v) not found", location)
}
// open the config file
reader, err = os.Open(location)
if err != nil {
return conf, fmt.Errorf("error opening local config file (%v): %v ", location, err)
}
}
return Parse(reader, location)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant