-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Don't mutate registered tls configs #600
Conversation
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.
This unfortunately breaks support for all Go versions prior to Go 1.8, as https://golang.org/pkg/crypto/tls/#Config.Clone seems to be available only in Go 1.8+
AUTHORS
Outdated
@@ -60,3 +62,4 @@ Zhenye Xie <xiezhenye at gmail.com> | |||
Barracuda Networks, Inc. | |||
Google Inc. | |||
Stripe Inc. | |||
Pivotal Inc. |
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.
Please keep this list sorted too (P < S)
The amount of clutter all these files introduce is unacceptable in my opinion. Can we maybe use something as simple as the following to create a shallow copy or do we get some problems with unexported fields (pointers) that also get copied? func cloneTLSConfig(cfg *tls.Config) *tls.Config {
clone := *cfg
return &clone
} |
To clarify, with Go 1.8+ we should use the Clone function, but is it possible the we break something with shallow copies pre Go 1.8? |
A shallow copy seems to be sufficient: https://play.golang.org/p/d6h9AvM6kI (compare with unexported fields in https://github.com/golang/go/blob/release-branch.go1.7/src/crypto/tls/common.go#L390) My suggestion would be to create 2 versions of the clone function: One for Go 1.8+ in |
Take a look at this example: https://play.golang.org/p/dqYUYAJEfk It illustrates when you copy the struct you are also copying the state of the mutex. Hence if the mutex is locked, when the struct is being copied, the program will deadlock. This was our motivation for not using the raw struct copy (ie. |
But why should the mutex on the original struct ever be locked? We just use it to clone it |
That mutex is being used here by this exported method. Thus it could be called at any point. We're flexible and can simplify the implementation as you suggested - but be aware a deadlock could occur. |
I think adding a note to the doc of RegisterTLSConfig that the TLS config is exclusively owned by the driver after registering it should be sufficient. |
FYI: govet failed for go1.7 due to the sync copies - we'll add an additional util for go1.7 |
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.
The stdlib actually contained the same workaround until the addition of Config.Clone: golang/go@d24f446#diff-4d34e6d5bd560e4ac6fd23ee5d9bda5fL119
But I think it isn't worth trying to silence go vet with some kind of workaround... so another special case for Go 1.7 😒
@@ -0,0 +1,9 @@ | |||
// +build go1.8 |
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.
Please add the following copyright header to the new files:
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package
//
// Copyright 2017 The Go-MySQL-Driver Authors. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
utils_go17.go
Outdated
// +build go1.7 | ||
// +build !go1.8 | ||
|
||
// Go MySQL Driver - A MySQL-Driver for Go's database/sql package |
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.
Please move them to the top, i.e. above the build tags (like https://github.com/go-sql-driver/mysql/pull/603/files)
Signed-off-by: Rebecca Chin <[email protected]>
Thanks for contributing! |
Signed-off-by: Dave Protasowski [email protected]
Description
tls.Configs in the registry are no longer mutated. They are cloned. This will fix the issue #536
Checklist