@@ -176,7 +176,9 @@ type ReconnectingPTYRequest struct {
176
176
func (c * WorkspaceAgentConn ) ReconnectingPTY (ctx context.Context , id uuid.UUID , height , width uint16 , command string ) (net.Conn , error ) {
177
177
ctx , span := tracing .StartSpan (ctx )
178
178
defer span .End ()
179
-
179
+ if ! c .AwaitReachable (ctx ) {
180
+ return nil , xerrors .Errorf ("workspace agent not reachable in time: %v" , ctx .Err ())
181
+ }
180
182
conn , err := c .DialContextTCP (ctx , netip .AddrPortFrom (WorkspaceAgentIP , WorkspaceAgentReconnectingPTYPort ))
181
183
if err != nil {
182
184
return nil , err
@@ -207,6 +209,9 @@ func (c *WorkspaceAgentConn) ReconnectingPTY(ctx context.Context, id uuid.UUID,
207
209
func (c * WorkspaceAgentConn ) SSH (ctx context.Context ) (net.Conn , error ) {
208
210
ctx , span := tracing .StartSpan (ctx )
209
211
defer span .End ()
212
+ if ! c .AwaitReachable (ctx ) {
213
+ return nil , xerrors .Errorf ("workspace agent not reachable in time: %v" , ctx .Err ())
214
+ }
210
215
return c .DialContextTCP (ctx , netip .AddrPortFrom (WorkspaceAgentIP , WorkspaceAgentSSHPort ))
211
216
}
212
217
@@ -235,6 +240,9 @@ func (c *WorkspaceAgentConn) SSHClient(ctx context.Context) (*ssh.Client, error)
235
240
func (c * WorkspaceAgentConn ) Speedtest (ctx context.Context , direction speedtest.Direction , duration time.Duration ) ([]speedtest.Result , error ) {
236
241
ctx , span := tracing .StartSpan (ctx )
237
242
defer span .End ()
243
+ if ! c .AwaitReachable (ctx ) {
244
+ return nil , xerrors .Errorf ("workspace agent not reachable in time: %v" , ctx .Err ())
245
+ }
238
246
speedConn , err := c .DialContextTCP (ctx , netip .AddrPortFrom (WorkspaceAgentIP , WorkspaceAgentSpeedtestPort ))
239
247
if err != nil {
240
248
return nil , xerrors .Errorf ("dial speedtest: %w" , err )
@@ -257,6 +265,9 @@ func (c *WorkspaceAgentConn) DialContext(ctx context.Context, network string, ad
257
265
_ , rawPort , _ := net .SplitHostPort (addr )
258
266
port , _ := strconv .ParseUint (rawPort , 10 , 16 )
259
267
ipp := netip .AddrPortFrom (WorkspaceAgentIP , uint16 (port ))
268
+ if ! c .AwaitReachable (ctx ) {
269
+ return nil , xerrors .Errorf ("workspace agent not reachable in time: %v" , ctx .Err ())
270
+ }
260
271
if network == "udp" {
261
272
return c .Conn .DialContextUDP (ctx , ipp )
262
273
}
@@ -317,7 +328,7 @@ func (c *WorkspaceAgentConn) apiClient() *http.Client {
317
328
// Disable keep alives as we're usually only making a single
318
329
// request, and this triggers goleak in tests
319
330
DisableKeepAlives : true ,
320
- DialContext : func (_ context.Context , network , addr string ) (net.Conn , error ) {
331
+ DialContext : func (ctx context.Context , network , addr string ) (net.Conn , error ) {
321
332
if network != "tcp" {
322
333
return nil , xerrors .Errorf ("network must be tcp" )
323
334
}
@@ -331,7 +342,11 @@ func (c *WorkspaceAgentConn) apiClient() *http.Client {
331
342
return nil , xerrors .Errorf ("request %q does not appear to be for http api" , addr )
332
343
}
333
344
334
- conn , err := c .DialContextTCP (context .Background (), netip .AddrPortFrom (WorkspaceAgentIP , WorkspaceAgentHTTPAPIServerPort ))
345
+ if ! c .AwaitReachable (ctx ) {
346
+ return nil , xerrors .Errorf ("workspace agent not reachable in time: %v" , ctx .Err ())
347
+ }
348
+
349
+ conn , err := c .DialContextTCP (ctx , netip .AddrPortFrom (WorkspaceAgentIP , WorkspaceAgentHTTPAPIServerPort ))
335
350
if err != nil {
336
351
return nil , xerrors .Errorf ("dial http api: %w" , err )
337
352
}
0 commit comments