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

spanner: canceled context is used to record stats #2660

Closed
nodirg opened this issue Jul 29, 2020 · 2 comments · Fixed by #2728
Closed

spanner: canceled context is used to record stats #2660

nodirg opened this issue Jul 29, 2020 · 2 comments · Fixed by #2728
Assignees
Labels
api: spanner Issues related to the Spanner API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: question Request for information or clarification. Not an issue.

Comments

@nodirg
Copy link

nodirg commented Jul 29, 2020

I have been reading Spanner client code and stumbled on this:

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
err := ws.prepareForWrite(ctx)
cancel()
if err != nil {
// Skip handling prepare error, session can be prepared in next
// cycle.
// Don't log about permission errors, which may be expected
// (e.g. using read-only auth).
serr := toSpannerError(err).(*Error)
if serr.Code != codes.PermissionDenied {
logf(hc.pool.sc.logger, "Failed to prepare session, error: %v", serr)
}
}
hc.pool.recycle(ws)
hc.pool.mu.Lock()
hc.pool.decNumBeingPreparedLocked(ctx)

note here that ctx is canceled in L1504 and then that context is used in L1517.

I don't have concrete problem that this caused, but this code does not look correct. Perhaps ctx variable in L1502 should be renamed

@nodirg nodirg added the triage me I really want to be triaged. label Jul 29, 2020
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Jul 29, 2020
@skuruppu skuruppu added priority: p2 Moderately-important priority. Fix may not be included in next release. type: question Request for information or clarification. Not an issue. and removed triage me I really want to be triaged. labels Jul 31, 2020
@skuruppu
Copy link
Contributor

@olavloite, if you could also take a look at this, that would be great.

CC @hengfengli

@skuruppu skuruppu assigned olavloite and unassigned skuruppu Aug 12, 2020
olavloite added a commit that referenced this issue Aug 13, 2020
The cancel() method should be called once all code that is executing in the given
context have finished. In this case, that also means after the stats recording that
uses the same context has finished.

Fixes #2660
@olavloite
Copy link
Contributor

@nodirg Thank you for your report. In this specific case it is as far as I can tell not really a problem, but I do agree with you that it looks a little bit suspicious. The reason that it is not really a problem in this case, is that the context is only used to include the tags that should be included with the statistics that are recorded.
I've moved the cancel() call to right after where it is used for the stats to prevent any confusion.

olavloite added a commit that referenced this issue Aug 14, 2020
The cancel() method should be called once all code that is executing in the given
context have finished. In this case, that also means after the stats recording that
uses the same context has finished.

Fixes #2660
tritone pushed a commit to tritone/google-cloud-go that referenced this issue Aug 25, 2020
…pis#2728)

The cancel() method should be called once all code that is executing in the given
context have finished. In this case, that also means after the stats recording that
uses the same context has finished.

Fixes googleapis#2660
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants