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

v2: Added ability to do context-aware PerformRequest #503

Merged
merged 11 commits into from
Jun 16, 2017
Merged

v2: Added ability to do context-aware PerformRequest #503

merged 11 commits into from
Jun 16, 2017

Conversation

utrack
Copy link
Contributor

@utrack utrack commented Mar 31, 2017

Small patch that adds PerformRequestC func which is usual PerformRequest that passes ctx to the HTTP client.

No API breakage or breakage of pre-1.7 builds.

@utrack utrack changed the title Added ability to do context-aware PerformRequest v2: Added ability to do context-aware PerformRequest Mar 31, 2017
@utrack
Copy link
Contributor Author

utrack commented Apr 24, 2017

Bump. Are you OK with this @olivere?

@olivere
Copy link
Owner

olivere commented Apr 24, 2017

@utrack v2 is rather old, so I'm not pushing too aggressively for that. There has also been some work recently to switch from golang.org/x/net/context to context, so this has to be done for v2 as well. We could introduce context in v2 as well, of course, but all other service interfaces have to be switched as well, not just PerformRequest.

I won't have time to look into it this week. Maybe next weekend.

@utrack
Copy link
Contributor Author

utrack commented Apr 24, 2017

Actually, v2 has no context-related code at all atm :) PerformRequestC is the only method that uses context as of this PR.
I didn't change original PerformRequest because of this - it would break the API.
I've used net/context for backwards compatibility, but it can be swapped in favour of vanilla context, of course.

@olivere
Copy link
Owner

olivere commented Apr 24, 2017

Yes. The PR mentioned above does exactly that. The "context" package is now available for 2 Go releases, and the majority of libraries are switching to it. I want elastic to do that as well.

However, the services need to be capable of using the PerformRequestC, which they are not with your change. Your change actually only adds context.Context to PerformRequest. If you're not sure what I mean, see this highlighted fragment from v3. It has to be done for all services in v2.

@utrack
Copy link
Contributor Author

utrack commented Apr 24, 2017

Oh, I see. I'll add support for other services then, thanks.

@olivere
Copy link
Owner

olivere commented Apr 24, 2017

@utrack Yes, that'd be very helpful. However, keep in mind that I won't be able to merge this week as I'm out of the office. Sorry.

@utrack
Copy link
Contributor Author

utrack commented May 23, 2017

@olivere Bump

@olivere
Copy link
Owner

olivere commented May 29, 2017

@utrack I'm sorry, I was on vacation last week and v2 is not my primary focus, so I updated 5.x first (and work on 6.x already). Please bear with me... it's just a matter of time. Your PR is very welcome, but I want to test it first.

client.go Outdated
if err := c.sniff(c.snifferTimeoutStartup); err != nil {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
if err := c.sniff(ctx, c.snifferTimeoutStartup); err != nil {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this and keep the code near to what we have in elastic.v5.

This opens more questions, but does not solve any issues. E.g. why a timeout of 10 seconds? Why cancel the context via timeout and pass a timeout?

client.go Outdated
@@ -868,7 +876,7 @@ func (c *Client) healthchecker() {
// the node state, it marks connections as dead, sets them alive etc.
// If healthchecks are disabled this is a no-op.
// The timeout specifies how long to wait for a response from Elasticsearch.
func (c *Client) healthcheck(timeout time.Duration, force bool) {
func (c *Client) healthcheck(ctx context.Context, timeout time.Duration, force bool) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Please keep the code as it is in elastic.v5.

@olivere
Copy link
Owner

olivere commented Jun 2, 2017

@utrack Please do not add code that pushes v2 into a different direction than v5. It might be useful, but it's hard enough to keep 3 versions of a codebase. It's even harder when they slightly differ.

@utrack
Copy link
Contributor Author

utrack commented Jun 2, 2017

Sorry for that, we've got the bug in production just yesterday. Without last two commits when ES cluster goes down - healthcheck waits for response indefinitely, blocking every other hc goroutine, leaking them and breaking the client. @olivere

@olivere
Copy link
Owner

olivere commented Jun 2, 2017

@utrack Now, that's a bug I'd like to see fixed. But I think we should address that in a separate issue/PR. Once you got the time, can you send a reproducible step-by-step/code snippet? It should also impact v3 and v5 then.

@utrack
Copy link
Contributor Author

utrack commented Jun 4, 2017

OK @olivere, I'll try to create a reproducible case in a separate PR then :)
Reverted last two commits.

@olivere olivere merged commit c3a2db2 into olivere:release-branch.v2 Jun 16, 2017
@olivere
Copy link
Owner

olivere commented Jun 16, 2017

Thanks for your support on getting context into v2. Even one of my projects will benefit from this :-)

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 this pull request may close these issues.

2 participants