Skip to content

namespace: Copy ttrpc metadata before setting header#3506

Merged
estesp merged 1 commit intocontainerd:masterfrom
darfux:copy_md_when_set_ttrpcheader
Aug 9, 2019
Merged

namespace: Copy ttrpc metadata before setting header#3506
estesp merged 1 commit intocontainerd:masterfrom
darfux:copy_md_when_set_ttrpcheader

Conversation

@darfux
Copy link
Copy Markdown
Contributor

@darfux darfux commented Aug 8, 2019

If there are multiple goroutines calling namespace.WithNamespace on a
ctx that already had namespace, there will be a data race when
withTTRPCNamespaceHeader calling MD.Set(). So we have to copy the md
before using it.

Fixes #3504
Signed-off-by: Li Yuxuan [email protected]

@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Aug 8, 2019

Build succeeded.

@darfux darfux force-pushed the copy_md_when_set_ttrpcheader branch from 16e16d4 to d18ae68 Compare August 8, 2019 16:47
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Aug 8, 2019

Build succeeded.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Aug 8, 2019

Codecov Report

Merging #3506 into master will increase coverage by 0.01%.
The diff coverage is 75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3506      +/-   ##
==========================================
+ Coverage   44.26%   44.27%   +0.01%     
==========================================
  Files         124      124              
  Lines       13675    13683       +8     
==========================================
+ Hits         6053     6058       +5     
- Misses       6687     6689       +2     
- Partials      935      936       +1
Flag Coverage Δ
#linux 48.05% <71.42%> (+0.01%) ⬆️
#windows 39.76% <75%> (+0.01%) ⬆️
Impacted Files Coverage Δ
namespaces/ttrpc.go 82.35% <75%> (-17.65%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a1c88e1...a3a3063. Read the comment docs.

@mxpv
Copy link
Copy Markdown
Member

mxpv commented Aug 8, 2019

@darfux @crosbymichael depends on map size, but wouldn't lock be more efficient here?

@crosbymichael
Copy link
Copy Markdown
Member

I think these maps will be very small, either work in this case

@mxpv
Copy link
Copy Markdown
Member

mxpv commented Aug 8, 2019

In this case I think we should copy slices as well since we're going to append to it (concurrently) later. This is what GRPC does as well: https://github.com/containerd/containerd/blob/master/vendor/google.golang.org/grpc/metadata/metadata.go#L130

@crosbymichael
Copy link
Copy Markdown
Member

Ahh, good catch, we should copy the slice

@darfux darfux force-pushed the copy_md_when_set_ttrpcheader branch from d18ae68 to 85ee8f8 Compare August 9, 2019 01:58
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Aug 9, 2019

Build succeeded.

Comment thread namespaces/ttrpc.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

use src here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ohhh, thanks!

@darfux darfux force-pushed the copy_md_when_set_ttrpcheader branch from 85ee8f8 to 7814bfb Compare August 9, 2019 02:26
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Aug 9, 2019

Build succeeded.

Copy link
Copy Markdown
Member

@fuweid fuweid left a comment

Choose a reason for hiding this comment

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

LGTM

If there are multiple goroutines calling `namespace.WithNamespace` on a
ctx that already had namespace, there will be a data race when
`withTTRPCNamespaceHeader` calling `MD.Set()`. So we have to copy the md
before using it.

Signed-off-by: Li Yuxuan <[email protected]>
@darfux darfux force-pushed the copy_md_when_set_ttrpcheader branch from 7814bfb to a3a3063 Compare August 9, 2019 05:16
@darfux darfux changed the title namespace: Copy ttrpc metadata before set header namespace: Copy ttrpc metadata before setting header Aug 9, 2019
@theopenlab-ci
Copy link
Copy Markdown

theopenlab-ci Bot commented Aug 9, 2019

Build succeeded.

@darfux
Copy link
Copy Markdown
Contributor Author

darfux commented Aug 9, 2019

I've updated the commit and added test cases, PTAL:) @fuweid @mxpv @crosbymichael

Copy link
Copy Markdown
Member

@fuweid fuweid 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
Copy Markdown
Member

@estesp estesp left a comment

Choose a reason for hiding this comment

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

LGTM

@estesp estesp merged commit ec4ad53 into containerd:master Aug 9, 2019
@darfux darfux deleted the copy_md_when_set_ttrpcheader branch August 12, 2019 02:13
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.

namespace.WithNamespace is not thread safe

6 participants