@@ -11,6 +11,7 @@ import (
1111 "os/exec"
1212 osuser "os/user"
1313 "path/filepath"
14+ "runtime"
1415 "strconv"
1516 "strings"
1617 "sync"
@@ -51,9 +52,20 @@ type RunExecutor struct {
5152 timestamp * MonotonicTimestamp
5253
5354 killDelay time.Duration
54- connectionTracker * connections.ConnectionTracker
55+ connectionTracker interface {
56+ GetNoConnectionsSecs () int64
57+ Track (ticker <- chan time.Time )
58+ Stop ()
59+ }
5560}
5661
62+ // stubConnectionTracker is a no-op implementation for when procfs is not available (only required for tests on darwin)
63+ type stubConnectionTracker struct {}
64+
65+ func (s * stubConnectionTracker ) GetNoConnectionsSecs () int64 { return 0 }
66+ func (s * stubConnectionTracker ) Track (ticker <- chan time.Time ) {}
67+ func (s * stubConnectionTracker ) Stop () {}
68+
5769func NewRunExecutor (tempDir string , homeDir string , workingDir string , sshPort int ) (* RunExecutor , error ) {
5870 mu := & sync.RWMutex {}
5971 timestamp := NewMonotonicTimestamp ()
@@ -65,15 +77,29 @@ func NewRunExecutor(tempDir string, homeDir string, workingDir string, sshPort i
6577 if err != nil {
6678 return nil , fmt .Errorf ("failed to parse current user uid: %w" , err )
6779 }
68- proc , err := procfs .NewDefaultFS ()
69- if err != nil {
70- return nil , fmt .Errorf ("failed to initialize procfs: %w" , err )
80+
81+ // Try to initialize procfs, but don't fail if it's not available (e.g., on macOS)
82+ var connectionTracker interface {
83+ GetNoConnectionsSecs () int64
84+ Track (ticker <- chan time.Time )
85+ Stop ()
7186 }
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- })
87+
88+ if runtime .GOOS == "linux" {
89+ proc , err := procfs .NewDefaultFS ()
90+ if err != nil {
91+ return nil , fmt .Errorf ("failed to initialize procfs: %w" , err )
92+ }
93+ connectionTracker = connections .NewConnectionTracker (connections.ConnectionTrackerConfig {
94+ Port : uint64 (sshPort ),
95+ MinConnDuration : 10 * time .Second , // shorter connections are likely from dstack-server
96+ Procfs : proc ,
97+ })
98+ } else {
99+ // Use stub connection tracker (only required for tests on darwin)
100+ connectionTracker = & stubConnectionTracker {}
101+ }
102+
77103 return & RunExecutor {
78104 tempDir : tempDir ,
79105 homeDir : homeDir ,
0 commit comments