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

invalid memory address or nil pointer dereference on [email protected]/elasticsearch.go:307 #913

Closed
defornia opened this issue Oct 25, 2024 · 0 comments · Fixed by #922
Closed

Comments

@defornia
Copy link

I've caught a panic from k8s log as belows.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x114653f]

goroutine 587 [running]:
github.com/elastic/go-elasticsearch/v7.(*Client).Perform(0xc000add000, 0xc002b338c0)
	/go/pkg/mod/github.com/elastic/go-elasticsearch/[email protected]/elasticsearch.go:307 +0x9f
github.com/elastic/go-elasticsearch/v7/esapi.UpdateByQueryRequest.Do({{0xc002bfbce0, 0x1, 0x1}, {0x0, 0x0, 0x0}, {0x2c68fe0, 0xc000052c40}, 0x0, {0x0, ...}, ...}, ...)
	/go/pkg/mod/github.com/elastic/go-elasticsearch/[email protected]/esapi/api.update_by_query.go:304 +0x1caa
github.com/elastic/go-elasticsearch/v7/esapi.New.newUpdateByQueryFunc.func101({0xc002bfbce0, 0x1, 0x1}, {0xc000052c60, 0x4, 0x495f8a?})
	/go/pkg/mod/github.com/elastic/go-elasticsearch/[email protected]/esapi/api.update_by_query.go:39 +0x14b

The method is as belows.

// Perform delegates to Transport to execute a request and return a response.
//
func (c *Client) Perform(req *http.Request) (*http.Response, error) {
	// ProductCheck validation. We skip this validation of we only want the
	// header validation. ResponseCheck path continues after original request.
	if !c.useResponseCheckOnly {
		// Launch product check for 7.x, request info, check header then payload.
		if err := c.doProductCheck(req.Context(), c.productCheck); err != nil {
			return nil, err
		}
	}

	// Retrieve the original request.
	res, err := c.Transport.Perform(req)

	// ResponseCheck path continues, we run the header check on the first answer from ES.
	if err == nil && (res.StatusCode >= 200 && res.StatusCode < 300){
		checkHeader := func(context.Context) error {
			return genuineCheckHeader(res.Header)
		}
		if err := c.doProductCheck(req.Context(), checkHeader); err != nil {
			res.Body.Close()
			return nil, err
		}
	}
	return res, err
}

There might be an issue where the code does not check if res is nil before accessing res.StatusCode, which could lead to the panic.

arp242 added a commit to arp242/go-elasticsearch that referenced this issue Nov 20, 2024
The http.Resonse will be nil on errors, so return early.

Fixes elastic#913
Anaethelion added a commit that referenced this issue Nov 27, 2024
* Check error in BaseClient.Perform

The http.Resonse will be nil on errors, so return early.

Fixes #913

* revert reordering of imports

---------

Co-authored-by: Laurent Saint-Félix <[email protected]>
Anaethelion added a commit that referenced this issue Nov 27, 2024
* Check error in BaseClient.Perform

The http.Resonse will be nil on errors, so return early.

Fixes #913

* revert reordering of imports

---------

Co-authored-by: Laurent Saint-Félix <[email protected]>
Anaethelion added a commit that referenced this issue Nov 27, 2024
* Check error in BaseClient.Perform

The http.Resonse will be nil on errors, so return early.

Fixes #913

* revert reordering of imports

---------

Co-authored-by: Laurent Saint-Félix <[email protected]>
Anaethelion added a commit that referenced this issue Nov 27, 2024
* Check error in BaseClient.Perform

The http.Resonse will be nil on errors, so return early.

Fixes #913

* revert reordering of imports

---------

Co-authored-by: Laurent Saint-Félix <[email protected]>
Anaethelion added a commit that referenced this issue Nov 27, 2024
* Check error in BaseClient.Perform

The http.Resonse will be nil on errors, so return early.

Fixes #913

* revert reordering of imports

---------

Co-authored-by: Martin Tournoij <[email protected]>
Anaethelion added a commit that referenced this issue Nov 27, 2024
* Check error in BaseClient.Perform

The http.Resonse will be nil on errors, so return early.

Fixes #913

* revert reordering of imports

---------

Co-authored-by: Martin Tournoij <[email protected]>
Anaethelion added a commit that referenced this issue Nov 27, 2024
* Check error in BaseClient.Perform

The http.Resonse will be nil on errors, so return early.

Fixes #913

* revert reordering of imports

---------

Co-authored-by: Martin Tournoij <[email protected]>
Anaethelion added a commit that referenced this issue Nov 27, 2024
* Check error in BaseClient.Perform

The http.Resonse will be nil on errors, so return early.

Fixes #913

* revert reordering of imports

---------

Co-authored-by: Martin Tournoij <[email protected]>
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

Successfully merging a pull request may close this issue.

1 participant