Skip to content

context: prevent creation of invalid contexts #37898

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

Closed
wants to merge 4 commits into from

Conversation

knusbaum
Copy link
Contributor

@knusbaum knusbaum commented Mar 17, 2020

This commit makes it impossible to create derived contexts with nil parents.
Previously it was possible to create derived contexts with nil parents, and
invalid contexts could propogate through the program. Eventually this can
cause a panic downstream, which is difficult to trace back to the source
of the error.

Although WithCancel and WithDeadline already panic if parent is nil, this adds explicit checks to give a useful message in the panic.

Fixes #37908

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added the cla: no Used by googlebot to label PRs as having an invalid CLA. The text of this label should not change. label Mar 17, 2020
@knusbaum
Copy link
Contributor Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change. and removed cla: no Used by googlebot to label PRs as having an invalid CLA. The text of this label should not change. labels Mar 17, 2020
@knusbaum knusbaum marked this pull request as ready for review March 17, 2020 10:02
@gopherbot
Copy link
Contributor

This PR (HEAD: f0ae60d) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/223777 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 1:

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
Within the next week or so, a maintainer will review your change and provide
feedback. See https://golang.org/doc/contribute.html#review for more info and
tips to get your patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11, it means that this CL will be reviewed as part of the next development
cycle. See https://golang.org/s/release for more details.


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

This commit makes it impossible to create derived contexts with nil
parents. Previously it was possible to create derived contexts with nil
parents, and invalid contexts could propagate through the program.
Eventually this could cause a panic downstream, which is difficult to trace
back to the source of the error.
@knusbaum knusbaum force-pushed the panic-on-bad-context branch from f0ae60d to f404080 Compare March 17, 2020 10:40
@gopherbot
Copy link
Contributor

This PR (HEAD: f404080) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/223777 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Ian Lance Taylor:

Patch Set 2: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 2:

TryBots beginning. Status page: https://farmer.golang.org/try?commit=fce6559c


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 2:

Build is still in progress...
This change failed on freebsd-amd64-12_0:
See https://storage.googleapis.com/go-build-log/fce6559c/freebsd-amd64-12_0_fc0c8ddf.log

Other builds still in progress; subsequent failure notices suppressed until final report. Consult https://build.golang.org/ to see whether they are new failures. Keep in mind that TryBots currently test exactly your git commit, without rebasing. If your commit's git parent is old, the failure might've already been fixed.


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 2: TryBot-Result-1

19 of 20 TryBots failed:
Failed on freebsd-amd64-12_0: https://storage.googleapis.com/go-build-log/fce6559c/freebsd-amd64-12_0_fc0c8ddf.log
Failed on openbsd-amd64-64: https://storage.googleapis.com/go-build-log/fce6559c/openbsd-amd64-64_49510652.log
Failed on linux-amd64: https://storage.googleapis.com/go-build-log/fce6559c/linux-amd64_3c6aaccd.log
Failed on linux-386: https://storage.googleapis.com/go-build-log/fce6559c/linux-386_6d73d868.log
Failed on windows-amd64-2016: https://storage.googleapis.com/go-build-log/fce6559c/windows-amd64-2016_1e31720d.log
Failed on linux-amd64-race: https://storage.googleapis.com/go-build-log/fce6559c/linux-amd64-race_127d27fe.log
Failed on windows-386-2008: https://storage.googleapis.com/go-build-log/fce6559c/windows-386-2008_784bd6c7.log
Failed on js-wasm: https://storage.googleapis.com/go-build-log/fce6559c/js-wasm_f8426c7d.log
Failed on android-amd64-emu: https://storage.googleapis.com/go-build-log/fce6559c/android-amd64-emu_1a36dc56.log
Failed on misc-compile-darwin: https://storage.googleapis.com/go-build-log/fce6559c/misc-compile-darwin_00771dc4.log
Failed on misc-compile-solaris: https://storage.googleapis.com/go-build-log/fce6559c/misc-compile-solaris_97350d83.log
Failed on misc-compile-linuxarm: https://storage.googleapis.com/go-build-log/fce6559c/misc-compile-linuxarm_b17e2be7.log
Failed on misc-compile-plan9: https://storage.googleapis.com/go-build-log/fce6559c/misc-compile-plan9_4905afe1.log
Failed on misc-compile-ppc: https://storage.googleapis.com/go-build-log/fce6559c/misc-compile-ppc_6f5e42c9.log
Failed on misc-compile-other: https://storage.googleapis.com/go-build-log/fce6559c/misc-compile-other_b9665683.log
Failed on misc-compile-freebsd: https://storage.googleapis.com/go-build-log/fce6559c/misc-compile-freebsd_594b8475.log
Failed on misc-compile-mips: https://storage.googleapis.com/go-build-log/fce6559c/misc-compile-mips_b5a01158.log
Failed on misc-compile-netbsd: https://storage.googleapis.com/go-build-log/fce6559c/misc-compile-netbsd_5f0326c6.log
Failed on misc-compile-openbsd: https://storage.googleapis.com/go-build-log/fce6559c/misc-compile-openbsd_7e64dab1.log

Consult https://build.golang.org/ to see whether they are new failures. Keep in mind that TryBots currently test exactly your git commit, without rebasing. If your commit's git parent is old, the failure might've already been fixed.


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR (HEAD: f051f22) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/223777 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Ian Lance Taylor:

Patch Set 5: Run-TryBot+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 5:

TryBots beginning. Status page: https://farmer.golang.org/try?commit=13b248c9


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 5:

Build is still in progress...
This change failed on freebsd-amd64-12_0:
See https://storage.googleapis.com/go-build-log/13b248c9/freebsd-amd64-12_0_391c37e5.log

Other builds still in progress; subsequent failure notices suppressed until final report. Consult https://build.golang.org/ to see whether they are new failures. Keep in mind that TryBots currently test exactly your git commit, without rebasing. If your commit's git parent is old, the failure might've already been fixed.


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Bryan C. Mills:

Patch Set 5: Code-Review+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 5: TryBot-Result-1

19 of 20 TryBots failed:
Failed on freebsd-amd64-12_0: https://storage.googleapis.com/go-build-log/13b248c9/freebsd-amd64-12_0_391c37e5.log
Failed on openbsd-amd64-64: https://storage.googleapis.com/go-build-log/13b248c9/openbsd-amd64-64_c359dd96.log
Failed on linux-amd64: https://storage.googleapis.com/go-build-log/13b248c9/linux-amd64_5524fca7.log
Failed on linux-386: https://storage.googleapis.com/go-build-log/13b248c9/linux-386_c55c00b0.log
Failed on windows-amd64-2016: https://storage.googleapis.com/go-build-log/13b248c9/windows-amd64-2016_b4d5c6b8.log
Failed on linux-amd64-race: https://storage.googleapis.com/go-build-log/13b248c9/linux-amd64-race_734924fe.log
Failed on windows-386-2008: https://storage.googleapis.com/go-build-log/13b248c9/windows-386-2008_08976e85.log
Failed on js-wasm: https://storage.googleapis.com/go-build-log/13b248c9/js-wasm_a31f26fd.log
Failed on android-amd64-emu: https://storage.googleapis.com/go-build-log/13b248c9/android-amd64-emu_87ef4ba3.log
Failed on misc-compile-solaris: https://storage.googleapis.com/go-build-log/13b248c9/misc-compile-solaris_b256c7fd.log
Failed on misc-compile-darwin: https://storage.googleapis.com/go-build-log/13b248c9/misc-compile-darwin_547aef61.log
Failed on misc-compile-linuxarm: https://storage.googleapis.com/go-build-log/13b248c9/misc-compile-linuxarm_43aed9ed.log
Failed on misc-compile-plan9: https://storage.googleapis.com/go-build-log/13b248c9/misc-compile-plan9_44f1d727.log
Failed on misc-compile-freebsd: https://storage.googleapis.com/go-build-log/13b248c9/misc-compile-freebsd_0cfccd31.log
Failed on misc-compile-other: https://storage.googleapis.com/go-build-log/13b248c9/misc-compile-other_0a062422.log
Failed on misc-compile-ppc: https://storage.googleapis.com/go-build-log/13b248c9/misc-compile-ppc_a2fafc5b.log
Failed on misc-compile-openbsd: https://storage.googleapis.com/go-build-log/13b248c9/misc-compile-openbsd_23ee252d.log
Failed on misc-compile-netbsd: https://storage.googleapis.com/go-build-log/13b248c9/misc-compile-netbsd_81b36658.log
Failed on misc-compile-mips: https://storage.googleapis.com/go-build-log/13b248c9/misc-compile-mips_33f979b0.log

Consult https://build.golang.org/ to see whether they are new failures. Keep in mind that TryBots currently test exactly your git commit, without rebasing. If your commit's git parent is old, the failure might've already been fixed.


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR (HEAD: 41768f1) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/223777 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Ian Lance Taylor:

Patch Set 7:

Does "go test context" pass on your system?


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Kyle Nusbaum:

Patch Set 7:

"go test context" passes now on my system.

Sorry, this is my first contribution and I was having trouble running the tests. I believe I have fixed them and it should all be passing now.


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Ian Lance Taylor:

Patch Set 7: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 7:

TryBots beginning. Status page: https://farmer.golang.org/try?commit=06103d5f


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 7: TryBot-Result+1

TryBots are happy.


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Bryan C. Mills:

Patch Set 7: Code-Review+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Ian Lance Taylor:

Patch Set 7:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR (HEAD: 1b7dadd) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/223777 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Ian Lance Taylor:

Patch Set 8: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 8:

TryBots beginning. Status page: https://farmer.golang.org/try?commit=b52ea257


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Kyle Nusbaum:

Patch Set 8:

(1 comment)

Fixed the trailing period in all panic messages.


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 8: TryBot-Result+1

TryBots are happy.


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

gopherbot pushed a commit that referenced this pull request Mar 18, 2020
This commit makes it impossible to create derived contexts with nil parents.
Previously it was possible to create derived contexts with nil parents, and
invalid contexts could propogate through the program. Eventually this can
cause a panic downstream, which is difficult to trace back to the source
of the error.

Although `WithCancel` and `WithDeadline` already panic if `parent` is `nil`, this adds explicit checks to give a useful message in the panic.

Fixes #37908

Change-Id: I70fd01f6539c1b0da0e775fc5457e32e7075e52c
GitHub-Last-Rev: 1b7dadd
GitHub-Pull-Request: #37898
Reviewed-on: https://go-review.googlesource.com/c/go/+/223777
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@gopherbot
Copy link
Contributor

Message from Ian Lance Taylor:

Patch Set 8: Code-Review+2

Thanks.


Please don’t reply on this GitHub thread. Visit golang.org/cl/223777.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR is being closed because golang.org/cl/223777 has been merged.

@gopherbot gopherbot closed this Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

context: panic when creating an invalid context
3 participants