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

runtime: don't spawn threads from locked Ms #20676

Closed
aclements opened this issue Jun 14, 2017 · 4 comments
Closed

runtime: don't spawn threads from locked Ms #20676

aclements opened this issue Jun 14, 2017 · 4 comments
Milestone

Comments

@aclements
Copy link
Member

Currently the runtime can spawn a new OS thread from essentially any M. This is bad if it attempts to spawn from a locked M that's locked because the goroutine on that M put the OS thread into a strange state. The new thread will inherit this state and start running other goroutines.

For example, this blog post describes the effects of this when trying to manipulate Linux namespaces from within a goroutine: https://www.weave.works/blog/linux-namespaces-and-go-don-t-mix

We should instead make sure we never spawn new threads from locked Ms. If we need to start a new thread while running on a locked M, we should forward the clone operation to a known-clean thread. We could either keep around a thread specifically for this purpose, or use the existing sysmon thread.

This is related to #20395, which is the other way a tainted thread can wind up back in the runtime's thread pool.

@aclements aclements added this to the Go1.10 milestone Jun 14, 2017
@aclements aclements self-assigned this Jun 14, 2017
@gopherbot
Copy link
Contributor

CL https://golang.org/cl/46033 mentions this issue.

mcwumbly added a commit to cloudfoundry/silk that referenced this issue Jun 21, 2017
Instead of switching into the container namespace
and getting the IP addresses from the device, lookup
the container metadata in our own datastore.

This avoids switching namespaces and simplifies the IFB
delete code a bit.

See also: golang/go#20676

[#145244693]
@jessfraz
Copy link
Contributor

cc @LK4D4 just figured you would be curious

@markdascher
Copy link

This is related to #13164, which was solved a different way.

Looks like the proposed solution has the same idea, just using an entire spare thread as the "known good" state instead of just initSigmask, which is likely to be redundant after this fix goes in. (Because ensureSigM calls LockOSThread already.)

jodh-intel added a commit to jodh-intel/runtimes that referenced this issue Sep 18, 2018
Move to golang version 1.10.4 -- the oldest stable golang release at the
time of writing -- since golang 1.10+ is needed to make namespace
handling safe.

See:

- golang/go#20676
- golang/go@2595fe7

Also bumped `languages.golang.meta.newest-version` to golang version
1.11, which is the newest stable release at the time of writing.

Fixes kata-containers#148.

Signed-off-by: James O. D. Hunt <[email protected]>
@wsc1
Copy link

wsc1 commented Sep 19, 2018

Just wanted to note this related message on golang-dev, as the notion of "clean thread" may be manipulated anyway via scheduling inheritance via pthread_attr or chrt linux and the like. Seems to me like a necessary and useful feature to isolate thread properties from threads created via package "C", but not via the OS.

jodh-intel added a commit to jodh-intel/runtimes that referenced this issue Sep 20, 2018
Move to golang version 1.10.4 -- the oldest stable golang release at the
time of writing -- since golang 1.10+ is needed to make namespace
handling safe.

Re-ordered a couple of structs (moved `sync.WaitGroup` fields) to keep
the `maligned` linter happy. Previously:

``
virtcontainers/pkg/mock/cc_proxy_mock.go:24:18:warning: struct of size 160 could be 152 (maligned)
virtcontainers/monitor.go:15:14:warning: struct of size 80 could be 72 (maligned)
```

See:

- golang/go#20676
- golang/go@2595fe7

Also bumped `languages.golang.meta.newest-version` to golang version
1.11, which is the newest stable release at the time of writing.

Fixes kata-containers#148.

Signed-off-by: James O. D. Hunt <[email protected]>
jodh-intel added a commit to jodh-intel/runtimes that referenced this issue Sep 20, 2018
Move to golang version 1.10.4 -- the oldest stable golang release at the
time of writing -- since golang 1.10+ is needed to make namespace
handling safe.

Re-ordered a couple of structs (moved `sync.WaitGroup` fields) to keep
the `maligned` linter happy. Previously:

``
virtcontainers/pkg/mock/cc_proxy_mock.go:24:18:warning: struct of size 160 could be 152 (maligned)
virtcontainers/monitor.go:15:14:warning: struct of size 80 could be 72 (maligned)
```

See:

- golang/go#20676
- golang/go@2595fe7

Also bumped `languages.golang.meta.newest-version` to golang version
1.11, which is the newest stable release at the time of writing.

Fixes kata-containers#148.

Signed-off-by: James O. D. Hunt <[email protected]>
jodh-intel added a commit to jodh-intel/runtimes that referenced this issue Oct 23, 2018
Move to golang version 1.10.4 -- the oldest stable golang release at the
time of writing -- since golang 1.10+ is needed to make namespace
handling safe.

Re-ordered a couple of structs (moved `sync.WaitGroup` fields) to keep
the `maligned` linter happy. Previously:

``
virtcontainers/pkg/mock/cc_proxy_mock.go:24:18:warning: struct of size 160 could be 152 (maligned)
virtcontainers/monitor.go:15:14:warning: struct of size 80 could be 72 (maligned)
```

See:

- golang/go#20676
- golang/go@2595fe7

Also bumped `languages.golang.meta.newest-version` to golang version
1.11, which is the newest stable release at the time of writing.

Fixes kata-containers#148.

Signed-off-by: James O. D. Hunt <[email protected]>
jodh-intel added a commit to jodh-intel/runtimes that referenced this issue Oct 23, 2018
Move to golang version 1.10.4 -- the oldest stable golang release at the
time of writing -- since golang 1.10+ is needed to make namespace
handling safe.

Re-ordered a couple of structs (moved `sync.WaitGroup` fields) to keep
the `maligned` linter happy. Previously:

``
virtcontainers/pkg/mock/cc_proxy_mock.go:24:18:warning: struct of size 160 could be 152 (maligned)
virtcontainers/monitor.go:15:14:warning: struct of size 80 could be 72 (maligned)
```

See:

- golang/go#20676
- golang/go@2595fe7

Also bumped `languages.golang.meta.newest-version` to golang version
1.11, which is the newest stable release at the time of writing.

Fixes kata-containers#148.

Signed-off-by: James O. D. Hunt <[email protected]>
jodh-intel added a commit to jodh-intel/runtimes that referenced this issue Oct 23, 2018
Move to golang version 1.10.4 -- the oldest stable golang release at the
time of writing -- since golang 1.10+ is needed to make namespace
handling safe.

Re-ordered a couple of structs (moved `sync.WaitGroup` fields) to keep
the `maligned` linter happy. Previously:

``
virtcontainers/pkg/mock/cc_proxy_mock.go:24:18:warning: struct of size 160 could be 152 (maligned)
virtcontainers/monitor.go:15:14:warning: struct of size 80 could be 72 (maligned)
```

See:

- golang/go#20676
- golang/go@2595fe7

Also bumped `languages.golang.meta.newest-version` to golang version
1.11, which is the newest stable release at the time of writing.

Fixes kata-containers#148.

Signed-off-by: James O. D. Hunt <[email protected]>
jodh-intel added a commit to jodh-intel/runtimes that referenced this issue Oct 23, 2018
Move to golang version 1.10.4 -- the oldest stable golang release at the
time of writing -- since golang 1.10+ is needed to make namespace
handling safe.

Re-ordered a couple of structs (moved `sync.WaitGroup` fields) to keep
the `maligned` linter happy. Previously:

``
virtcontainers/pkg/mock/cc_proxy_mock.go:24:18:warning: struct of size 160 could be 152 (maligned)
virtcontainers/monitor.go:15:14:warning: struct of size 80 could be 72 (maligned)
```

See:

- golang/go#20676
- golang/go@2595fe7

Also bumped `languages.golang.meta.newest-version` to golang version
1.11, which is the newest stable release at the time of writing.

Fixes kata-containers#148.

Signed-off-by: James O. D. Hunt <[email protected]>
zklei pushed a commit to zklei/runtime that referenced this issue Nov 22, 2018
Move to golang version 1.10.4 -- the oldest stable golang release at the
time of writing -- since golang 1.10+ is needed to make namespace
handling safe.

Re-ordered a couple of structs (moved `sync.WaitGroup` fields) to keep
the `maligned` linter happy. Previously:

``
virtcontainers/pkg/mock/cc_proxy_mock.go:24:18:warning: struct of size 160 could be 152 (maligned)
virtcontainers/monitor.go:15:14:warning: struct of size 80 could be 72 (maligned)
```

See:

- golang/go#20676
- golang/go@2595fe7

Also bumped `languages.golang.meta.newest-version` to golang version
1.11, which is the newest stable release at the time of writing.

Fixes kata-containers#148.

Signed-off-by: James O. D. Hunt <[email protected]>
brb added a commit to brb/netns that referenced this issue Dec 21, 2018
This prevents netns from being used on older Go runtimes on which it's
not safe to perform any state manipulations of a scheduling thread
(golang/go#20676).

Signed-off-by: Martynas Pumputis <[email protected]>
@golang golang locked and limited conversation to collaborators Sep 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants