-
Notifications
You must be signed in to change notification settings - Fork 649
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
[1.3] bucket.Put: copy key before seek #639
Conversation
@@ -288,18 +288,23 @@ func (b *Bucket) Put(key []byte, value []byte) error { | |||
return ErrValueTooLarge | |||
} | |||
|
|||
// Insert into node. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's related to #550.
If it's not accepted, I can use key
here. Or I can cherry-pick 550 first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
As per `go build -gcflags -m ./... 2>&1`: Old behaviour: ``` ./bucket.go:148:31: leaking param: key ./bucket.go:192:42: leaking param: key ./bucket.go:271:22: leaking param: key ``` Now: ``` ./bucket.go:148:31: key does not escape ./bucket.go:192:42: key does not escape ./bucket.go:271:22: key does not escape ``` Signed-off-by: Evgenii Stratonikov <[email protected]> (cherry picked from commit 71a59ca) Signed-off-by: Wei Fu <[email protected]>
581c892
to
31b5a34
Compare
bucket.go
Outdated
c.node().put(key, key, value, 0, bucketLeafFlag) | ||
// Tip: Use a new variable `newKey` instead of reusing the existing `key` to prevent | ||
// it from being marked as leaking, and accordingly cannot be allocated on stack. | ||
newKey := cloneBytes(key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should clone the key before seek
(line 167). Please update the main branch firstly. Thanks.
Signed-off-by: Wei Fu <[email protected]> (cherry picked from commit 324df9c) Signed-off-by: Wei Fu <[email protected]>
Signed-off-by: Wei Fu <[email protected]> (cherry picked from commit 1b08078) Signed-off-by: Wei Fu <[email protected]>
Application might change key value after seeking and before real put. This unexpected behaviour could corrupt database. When users file issue, maintainers doesn't know application behaviour. It could be caused by data race. This patch is to prevent such case and save maintainers' time. Signed-off-by: Wei Fu <[email protected]> (cherry picked from commit a05ec68) Signed-off-by: Wei Fu <[email protected]>
It's follow-up of etcd-io#637. Signed-off-by: Wei Fu <[email protected]> (cherry picked from commit 62d8026) Signed-off-by: Wei Fu <[email protected]>
31b5a34
to
fabe2fb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Thanks
cherry-pick: