@@ -11,6 +11,7 @@ import (
1111 "os/exec"
1212 osuser "os/user"
1313 "path/filepath"
14+ "runtime"
1415 "strconv"
1516 "strings"
1617 "sync"
@@ -27,6 +28,12 @@ import (
2728 "github.com/prometheus/procfs"
2829)
2930
31+ type ConnectionTracker interface {
32+ GetNoConnectionsSecs () int64
33+ Track (ticker <- chan time.Time )
34+ Stop ()
35+ }
36+
3037type RunExecutor struct {
3138 tempDir string
3239 homeDir string
@@ -51,9 +58,16 @@ type RunExecutor struct {
5158 timestamp * MonotonicTimestamp
5259
5360 killDelay time.Duration
54- connectionTracker * connections. ConnectionTracker
61+ connectionTracker ConnectionTracker
5562}
5663
64+ // stubConnectionTracker is a no-op implementation for when procfs is not available (only required for tests on darwin)
65+ type stubConnectionTracker struct {}
66+
67+ func (s * stubConnectionTracker ) GetNoConnectionsSecs () int64 { return 0 }
68+ func (s * stubConnectionTracker ) Track (ticker <- chan time.Time ) {}
69+ func (s * stubConnectionTracker ) Stop () {}
70+
5771func NewRunExecutor (tempDir string , homeDir string , workingDir string , sshPort int ) (* RunExecutor , error ) {
5872 mu := & sync.RWMutex {}
5973 timestamp := NewMonotonicTimestamp ()
@@ -65,15 +79,25 @@ func NewRunExecutor(tempDir string, homeDir string, workingDir string, sshPort i
6579 if err != nil {
6680 return nil , fmt .Errorf ("failed to parse current user uid: %w" , err )
6781 }
68- proc , err := procfs .NewDefaultFS ()
69- if err != nil {
70- return nil , fmt .Errorf ("failed to initialize procfs: %w" , err )
82+
83+ // Try to initialize procfs, but don't fail if it's not available (e.g., on macOS)
84+ var connectionTracker ConnectionTracker
85+
86+ if runtime .GOOS == "linux" {
87+ proc , err := procfs .NewDefaultFS ()
88+ if err != nil {
89+ return nil , fmt .Errorf ("failed to initialize procfs: %w" , err )
90+ }
91+ connectionTracker = connections .NewConnectionTracker (connections.ConnectionTrackerConfig {
92+ Port : uint64 (sshPort ),
93+ MinConnDuration : 10 * time .Second , // shorter connections are likely from dstack-server
94+ Procfs : proc ,
95+ })
96+ } else {
97+ // Use stub connection tracker (only required for tests on darwin)
98+ connectionTracker = & stubConnectionTracker {}
7199 }
72- connectionTracker := connections .NewConnectionTracker (connections.ConnectionTrackerConfig {
73- Port : uint64 (sshPort ),
74- MinConnDuration : 10 * time .Second , // shorter connections are likely from dstack-server
75- Procfs : proc ,
76- })
100+
77101 return & RunExecutor {
78102 tempDir : tempDir ,
79103 homeDir : homeDir ,
0 commit comments