diff --git a/api/allocations_exec.go b/api/allocations_exec.go index ea34b2450..9f5e0e299 100644 --- a/api/allocations_exec.go +++ b/api/allocations_exec.go @@ -62,7 +62,12 @@ func (s *execSession) run(ctx context.Context) (exitCode int, err error) { } func (s *execSession) startConnection() (*websocket.Conn, error) { - nodeClient, _ := s.client.GetNodeClientWithTimeout(s.alloc.NodeID, ClientConnTimeout, s.q) + // First, attempt to connect to the node directly, but may fail due to network isolation + // and network errors. Fallback to using server-side forwarding instead. + nodeClient, err := s.client.GetNodeClientWithTimeout(s.alloc.NodeID, ClientConnTimeout, s.q) + if err == NodeDownErr { + return nil, NodeDownErr + } q := s.q if q == nil { diff --git a/vendor/github.com/hashicorp/nomad/api/allocations_exec.go b/vendor/github.com/hashicorp/nomad/api/allocations_exec.go index ea34b2450..9f5e0e299 100644 --- a/vendor/github.com/hashicorp/nomad/api/allocations_exec.go +++ b/vendor/github.com/hashicorp/nomad/api/allocations_exec.go @@ -62,7 +62,12 @@ func (s *execSession) run(ctx context.Context) (exitCode int, err error) { } func (s *execSession) startConnection() (*websocket.Conn, error) { - nodeClient, _ := s.client.GetNodeClientWithTimeout(s.alloc.NodeID, ClientConnTimeout, s.q) + // First, attempt to connect to the node directly, but may fail due to network isolation + // and network errors. Fallback to using server-side forwarding instead. + nodeClient, err := s.client.GetNodeClientWithTimeout(s.alloc.NodeID, ClientConnTimeout, s.q) + if err == NodeDownErr { + return nil, NodeDownErr + } q := s.q if q == nil {