From 592c39fb1dce5f036f344c70f30657f0cc3b3eff Mon Sep 17 00:00:00 2001 From: CallanTaylor Date: Tue, 19 Nov 2019 13:57:25 +1300 Subject: [PATCH 1/4] Close file --- lib/common/util.go | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/common/util.go b/lib/common/util.go index 41f8b3c..3c4a57b 100755 --- a/lib/common/util.go +++ b/lib/common/util.go @@ -119,6 +119,7 @@ func ReadAllFromFile(filePath string) ([]byte, error) { if err != nil { return nil, err } + defer f.Close() return ioutil.ReadAll(f) } From e429b17e63c42b9db64c05e8d363ebf2fb6f37d3 Mon Sep 17 00:00:00 2001 From: ffdfgdfg Date: Fri, 29 Nov 2019 00:23:55 +0800 Subject: [PATCH 2/4] strange 64bit alignment --- lib/mux/queue.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/mux/queue.go b/lib/mux/queue.go index 212563c..6f14faa 100644 --- a/lib/mux/queue.go +++ b/lib/mux/queue.go @@ -209,10 +209,15 @@ func NewListElement(buf []byte, l uint16, part bool) (element *common.ListElemen } type ReceiveWindowQueue struct { - lengthWait uint64 chain *bufChain stopOp chan struct{} readOp chan struct{} + lengthWait uint64 // really strange ???? need put here + // https://golang.org/pkg/sync/atomic/#pkg-note-BUG + // On non-Linux ARM, the 64-bit functions use instructions unavailable before the ARMv6k core. + // On ARM, x86-32, and 32-bit MIPS, it is the caller's responsibility + // to arrange for 64-bit alignment of 64-bit words accessed atomically. + // The first word in a variable or in an allocated struct, array, or slice can be relied upon to be 64-bit aligned. timeout time.Time } From 88dcea59ec0282e13995de7d067ada657a99f4a8 Mon Sep 17 00:00:00 2001 From: Callan Taylor <31758692+CallanTaylor@users.noreply.github.com> Date: Mon, 2 Dec 2019 04:29:36 +1300 Subject: [PATCH 4/4] Stop tickers to free up resources (#263) --- bridge/bridge.go | 1 + client/control.go | 2 ++ client/local.go | 1 + lib/mux/mux.go | 3 ++- server/server.go | 2 ++ 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bridge/bridge.go b/bridge/bridge.go index e372908..ea5c282 100755 --- a/bridge/bridge.go +++ b/bridge/bridge.go @@ -342,6 +342,7 @@ func (s *Bridge) SendLinkInfo(clientId int, link *conn.Link, t *file.Tunnel) (ta func (s *Bridge) ping() { ticker := time.NewTicker(time.Second * 5) + defer ticker.Stop() for { select { case <-ticker.C: diff --git a/client/control.go b/client/control.go index 3260113..5589d11 100644 --- a/client/control.go +++ b/client/control.go @@ -369,6 +369,7 @@ func sendP2PTestMsg(localConn *net.UDPConn, remoteAddr1, remoteAddr2, remoteAddr } logs.Trace("try send test packet to target %s", addr) ticker := time.NewTicker(time.Millisecond * 500) + defer ticker.Stop() for { select { case <-ticker.C: @@ -394,6 +395,7 @@ func sendP2PTestMsg(localConn *net.UDPConn, remoteAddr1, remoteAddr2, remoteAddr return } ticker := time.NewTicker(time.Second * 2) + defer ticker.Stop() for { select { case <-ticker.C: diff --git a/client/local.go b/client/local.go index 55b9df9..06057ca 100644 --- a/client/local.go +++ b/client/local.go @@ -117,6 +117,7 @@ func StartLocalServer(l *config.LocalServer, config *config.CommonConfig) error func handleUdpMonitor(config *config.CommonConfig, l *config.LocalServer) { ticker := time.NewTicker(time.Second * 1) + defer ticker.Stop() for { select { case <-ticker.C: diff --git a/lib/mux/mux.go b/lib/mux/mux.go index a43510a..02b017a 100644 --- a/lib/mux/mux.go +++ b/lib/mux/mux.go @@ -173,9 +173,9 @@ func (s *Mux) ping() { s.sendInfo(common.MUX_PING_FLAG, common.MUX_PING, now) // send the ping flag and get the latency first ticker := time.NewTicker(time.Second * 5) + defer ticker.Stop() for { if s.IsClose { - ticker.Stop() break } select { @@ -198,6 +198,7 @@ func (s *Mux) ping() { } atomic.AddUint32(&s.pingOk, 1) } + return }() } diff --git a/server/server.go b/server/server.go index 5e72617..911fde5 100644 --- a/server/server.go +++ b/server/server.go @@ -109,6 +109,7 @@ func StartNewServer(bridgePort int, cnf *file.Tunnel, bridgeType string) { func dealClientFlow() { ticker := time.NewTicker(time.Minute) + defer ticker.Stop() for { select { case <-ticker.C: @@ -430,6 +431,7 @@ func GetDashboardData() map[string]interface{} { func flowSession(m time.Duration) { ticker := time.NewTicker(m) + defer ticker.Stop() for { select { case <-ticker.C: