Skip to content

Commit

Permalink
Stop tickers to free up resources (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
CallanTaylor authored and ffdfgdfg committed Dec 1, 2019
1 parent bdf12fe commit 88dcea5
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions client/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions client/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion lib/mux/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -198,6 +198,7 @@ func (s *Mux) ping() {
}
atomic.AddUint32(&s.pingOk, 1)
}
return
}()
}

Expand Down
2 changes: 2 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 88dcea5

Please sign in to comment.