From d695429edab586b3af14ebd36a4b010796f012dc Mon Sep 17 00:00:00 2001 From: ginuerzh Date: Thu, 6 Dec 2018 11:48:38 +0800 Subject: [PATCH] fix data race in kcp --- kcp.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kcp.go b/kcp.go index c98500a..9d4c4ce 100644 --- a/kcp.go +++ b/kcp.go @@ -66,7 +66,7 @@ func (c *KCPConfig) Init() { var ( // DefaultKCPConfig is the default KCP config. - DefaultKCPConfig = &KCPConfig{ + DefaultKCPConfig = KCPConfig{ Key: "it's a secrect", Crypt: "aes", Mode: "fast", @@ -99,7 +99,8 @@ type kcpTransporter struct { // KCPTransporter creates a Transporter that is used by KCP proxy client. func KCPTransporter(config *KCPConfig) Transporter { if config == nil { - config = DefaultKCPConfig + config = &KCPConfig{} + *config = DefaultKCPConfig } config.Init() @@ -227,7 +228,8 @@ type kcpListener struct { // KCPListener creates a Listener for KCP proxy server. func KCPListener(addr string, config *KCPConfig) (Listener, error) { if config == nil { - config = DefaultKCPConfig + config = &KCPConfig{} + *config = DefaultKCPConfig } config.Init()