Merge pull request #585 from unistack-org/transport2

transport memory: fix races
This commit is contained in:
Asim Aslam 2019-07-13 19:38:22 -07:00 committed by GitHub
commit a549f92dec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,10 +12,6 @@ import (
"github.com/micro/go-micro/transport"
)
var (
r = rand.New(rand.NewSource(time.Now().UnixNano()))
)
type memorySocket struct {
recv chan *transport.Message
send chan *transport.Message
@ -178,7 +174,7 @@ func (m *memoryTransport) Listen(addr string, opts ...transport.ListenOption) (t
// if zero port then randomly assign one
if len(parts) > 1 && parts[len(parts)-1] == "0" {
i := r.Intn(10000)
i := rand.Intn(20000)
// set addr with port
addr = fmt.Sprintf("%s:%d", parts[:len(parts)-1], 10000+i)
}
@ -215,6 +211,7 @@ func (m *memoryTransport) String() string {
}
func NewTransport(opts ...transport.Option) transport.Transport {
rand.Seed(time.Now().UnixNano())
var options transport.Options
for _, o := range opts {
o(&options)