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

Switch from x/net/context to context #1038

Merged
merged 2 commits into from
May 12, 2018
Merged

Conversation

kolyshkin
Copy link
Contributor

Since go 1.7, "context" is a standard package. Since go 1.9, x/net/context merely provides some types aliased to those in the standard context package, so there is no functional change.

The changes were performed by the following script:

for f in $(git ls-files \*.go | grep -v ^vendor/); do
	sed -i 's|golang.org/x/net/context|context|' $f
       	goimports -w $f
	awk '/^$/ {e=1; next;}
		/\t"context"$/ {e=0;}
		{if (e) {print ""; e=0}; print;}' < $f > $f.new && \
			mv $f.new $f
	goimports -w $f
done

Similar PRs:

@vdemeester
Copy link
Collaborator

cli/command/container/run.go:159::error: the cancelFun function is not used on all paths (possible context leak) (vet)
cli/command/container/run.go:164::error: this return statement may be reached without using the cancelFun var defined on line 159 (vet)
cli/command/container/start.go:57::error: the cancelFun function is not used on all paths (possible context leak) (vet)
cli/command/container/start.go:63::error: this return statement may be reached without using the cancelFun var defined on line 57 (vet)
@kolyshkin
Copy link
Contributor Author

Those are the errors uncovered by the switch to the standard package (that's a deficiency in go vet I guess). I have added commits to fix those.

@thaJeztah
Copy link
Member

thaJeztah commented May 9, 2018

Looks like there's still some linting issues;

Successfully built 52e421ae6713
Successfully tagged cli-linter:12013
cli/command/container/run.go:163::error: the cancelFun function is not used on all paths (possible context leak) (vet)
cli/command/container/run.go:169::error: this return statement may be reached without using the cancelFun var defined on line 163 (vet)
Exited with code 1
Copy link
Collaborator

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

two nits, but no real blocker, so let me know if you want to update, otherwise we can merge as-is

LGTM

@@ -5,14 +5,15 @@ import (
"strings"
"testing"

"context"
Copy link
Member

Choose a reason for hiding this comment

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

nit: should be grouped with the other stdlib imports

@@ -4,6 +4,8 @@ import (
"fmt"
"sort"

"context"
Copy link
Member

Choose a reason for hiding this comment

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

nit: should be grouped with the above

@kolyshkin
Copy link
Contributor Author

Sure, let me update it. I was curious why my script was not working and it is because there are more than 2 groups of imports (separated by an empty line), and in case the "context" is not in the first two groups, one need to repeat the awk/goimports mantra twice.

Patch updated.

Since go 1.7, "context" is a standard package. Since go 1.9,
x/net/context merely provides some types aliased to those in
the standard context package.

The changes were performed by the following script:

for f in $(git ls-files \*.go | grep -v ^vendor/); do
	sed -i 's|golang.org/x/net/context|context|' $f
	goimports -w $f
	for i in 1 2; do
		awk '/^$/ {e=1; next;}
			/\t"context"$/ {e=0;}
			{if (e) {print ""; e=0}; print;}' < $f > $f.new && \
				mv $f.new $f
		goimports -w $f
	done
done

[v2: do awk/goimports fixup twice]
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Switch from x/net/context to context made "go vet" see the previously
unseen errors:

> cli/command/container/start.go:57::error: the cancelFun function is
> not used on all paths (possible context leak) (vet)
> cli/command/container/start.go:63::error: this return statement may be
> reached without using the cancelFun var defined on line 57 (vet)

> cli/command/container/run.go:159::error: the cancelFun function is not
> used on all paths (possible context leak) (vet)
> cli/command/container/run.go:164::error: this return statement may be
> reached without using the cancelFun var defined on line 159 (vet)

Do call the cancel function.

Note we might end up calling it twice which is fine as long as I can see
from the Go 1.10 source code.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment