-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[fix] Close Elasticsearch client properly #4754
Conversation
Signed-off-by: Lauquik <laukik.22010776@viit.ac.in>
Signed-off-by: Lauquik <laukik.22010776@viit.ac.in>
plugin/storage/es/factory_test.go
Outdated
@@ -360,7 +361,14 @@ func TestPasswordFromFileErrors(t *testing.T) { | |||
|
|||
logger, buf := testutils.NewEchoLogger(t) | |||
require.NoError(t, f.Initialize(metrics.NullFactory, logger)) | |||
defer f.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to do manual closing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when i tested it, this was the error that i encountered
--- FAIL: TestPasswordFromFileErrors (0.05s)
logger.go:130: 2023-09-12T22:33:23.038+0530 INFO Elasticsearch detected {"version": 6}
logger.go:130: 2023-09-12T22:33:23.038+0530 INFO loaded new password of length 14 from file
logger.go:130: 2023-09-12T22:33:23.038+0530 ERROR failed to recreate Elasticsearch client with new password {"error": "no servers specified"}
logger.go:130: 2023-09-12T22:33:23.038+0530 INFO loaded new password of length 14 from file
logger.go:130: 2023-09-12T22:33:23.038+0530 ERROR failed to recreate Elasticsearch client with new password {"error": "no servers specified"}
logger.go:130: 2023-09-12T22:33:23.038+0530 ERROR failed to reload password for Elasticsearch client {"error": "open /tmp/TestPasswordFromFileErrors2482467054/001/pwd: no such file or directory"}
logger.go:130: 2023-09-12T22:33:23.038+0530 ERROR failed to reload password for Elasticsearch client {"error": "open /tmp/TestPasswordFromFileErrors2482467054/001/pwd: no such file or directory"}
logger.go:130: 2023-09-12T22:33:23.038+0530 INFO Received event {"event": "REMOVE \"/tmp/TestPasswordFromFileErrors2482467054/001/pwd\""}
logger.go:130: 2023-09-12T22:33:23.038+0530 WARN Unable to read the file {"file": "/tmp/TestPasswordFromFileErrors2482467054/001/pwd", "error": "open /tmp/TestPasswordFromFileErrors2482467054/001/pwd: no such file or directory"}
logger.go:130: 2023-09-12T22:33:23.038+0530 ERROR failed to reload password for Elasticsearch client {"error": "open /tmp/TestPasswordFromFileErrors2482467054/001/pwd: no such file or directory"}
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xc88bd5]
goroutine 120 [running]:
testing.tRunner.func1.2({0xd89360, 0x1631cc0})
/usr/local/go/src/testing/testing.go:1545 +0x238
testing.tRunner.func1()
/usr/local/go/src/testing/testing.
i dont' know the exact reason but looks like when clients are closed onClientPasswordChange() function was unable to
loadTokenFromFile and threw the error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the full stack trace of the panic? It does not show any of our functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
goroutine 120 [running]:
testing.tRunner.func1.2({0xd89360, 0x1631cc0})
/usr/local/go/src/testing/testing.go:1545 +0x238
testing.tRunner.func1()
/usr/local/go/src/testing/testing.go:1548 +0x397
panic({0xd89360?, 0x1631cc0?})
/usr/local/go/src/runtime/panic.go:914 +0x21f
github.com/jaegertracing/jaeger/plugin/storage/es.(*Factory).getArchiveClient(...)
/mnt/j/cncf/jaeger/plugin/storage/es/factory.go:144
github.com/jaegertracing/jaeger/plugin/storage/es.(*Factory).Close(0xc00023c230)
/mnt/j/cncf/jaeger/plugin/storage/es/factory.go:292 +0x275
github.com/jaegertracing/jaeger/plugin/storage/es.TestPasswordFromFileErrors(0xc00070e1a0)
/mnt/j/cncf/jaeger/plugin/storage/es/factory_test.go:386 +0x585
testing.tRunner(0xc00070e1a0, 0xf1c0d8)
/usr/local/go/src/testing/testing.go:1595 +0xff
created by testing.(*T).Run in goroutine 1
/usr/local/go/src/testing/testing.go:1648 +0x3ad
exit status 2
FAIL github.com/jaegertracing/jaeger/plugin/storage/es 0.207s
this is the remaining error log but here onClientPasswordChange is not mentioned i figured it out by myself , i maybe wrong
but after executing defer f.Close() the test calls onClientPasswordChange() this function
and "f.logger.Error("failed to reload password for Elasticsearch client", zap.Error(err)) " this error handle is presenet in that function (onClientPasswordChange)
and we can see the Zap.Error log which says {"error": "no servers specified"}
i tried rerun the test without closing factory resources and the test passed , i manyally closed the watchers and test still passed but after clsoing clients it didn't passed
plugin/storage/es/factory.go
Outdated
errs = append(errs, | ||
f.Options.GetPrimary().TLS.Close(), | ||
f.getArchiveClient().Close(), | ||
f.getPrimaryClient().Close()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking this would need to be more complicated, but I think you're right, as long as we close the watchers above, there's no more concurrency with the clients being swapped, so it's safe to close them like this.
👍
Codecov ReportPatch coverage is
📢 Thoughts on this report? Let us know!. |
Signed-off-by: Yuri Shkuro <github@ysh.us>
@Lauquik thanks for PR! |
Which problem is this PR solving?
Description of the changes
How was this change tested?
Checklist
jaeger
:make lint test
jaeger-ui
:yarn lint
andyarn test