Skip to content

Commit 002fd9f

Browse files
AdaAibabyarkamar
andauthored
fix(envd): replace time.Sleep with ticker in ScanAndBroadcast for prompt shutdown (#3374)
Replace `time.Sleep` with `time.NewTicker` so `scanExit` and the tick interval are waited on simultaneously in a single `select`. `Destroy()` now unblocks the goroutine instantly, regardless of how far into the current interval it is. Fixes: #3356 Co-authored-by: Petr Vaněk <petr.vanek@e2b.dev>
1 parent e2255f0 commit 002fd9f

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

packages/envd/internal/port/scan.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ func (s *Scanner) Unsubscribe(sub *ScannerSubscriber) {
4343

4444
// ScanAndBroadcast starts scanning open TCP ports and broadcasts every open port to all subscribers.
4545
func (s *Scanner) ScanAndBroadcast() {
46+
ticker := time.NewTicker(s.period)
47+
defer ticker.Stop()
48+
4649
for {
4750
// tcp monitors both ipv4 and ipv6 connections.
4851
processes, _ := net.Connections("tcp")
@@ -52,8 +55,7 @@ func (s *Scanner) ScanAndBroadcast() {
5255
select {
5356
case <-s.scanExit:
5457
return
55-
default:
56-
time.Sleep(s.period)
58+
case <-ticker.C:
5759
}
5860
}
5961
}

packages/envd/pkg/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package pkg
22

3-
const Version = "0.6.10"
3+
const Version = "0.6.11"

0 commit comments

Comments
 (0)