aerokube / ggr

A lightweight load balancer used to create big Selenium clusters
https://aerokube.com/ggr/latest/
Apache License 2.0
314 stars 74 forks source link

Response is not-nil if error is nil #376

Closed alexandear closed 1 year ago

alexandear commented 1 year ago

This PR removes if resp != nil check when creating a session in proxy.go.

The resp object cannot be nil in this code, as it is assigned the return value of httpClient.Do(req) method call, which returns a non-nil response object or an `error if the request could not be sent or the server returns an error response. From the documentation:

If the returned error is nil, the Response will contain a non-nil Body which the user is expected to close. ... The request Body, if non-nil, will be closed by the underlying Transport, even on errors.

Actually, the code has leaked resources, but in proxy_test.go. Every call to http.Get must be accompanied by rsp.Body.Close() call. These places can be found by bodyclose linter.

vania-pooh commented 1 year ago

@alexandear correct, but let's just do defer resp.Body.Close() after err != nil check. Logging is not needed here.

alexandear commented 1 year ago

@vania-pooh done

vania-pooh commented 1 year ago

@alexandear thank you for contribution.