diff --git a/rpc_proxy.go b/rpc_proxy.go index d60ed134..25eb3c0b 100644 --- a/rpc_proxy.go +++ b/rpc_proxy.go @@ -304,7 +304,12 @@ func (p *rpcProxy) makeDirector(allowLitRPC bool) func(ctx context.Context, // since it must either be an lnd call or something that'll be // handled by the integrated daemons that are hooking into lnd's // gRPC server. - handled, conn := p.subServerMgr.GetRemoteConn(requestURI) + handled, conn, err := p.subServerMgr.GetRemoteConn(requestURI) + if err != nil { + return outCtx, nil, status.Errorf( + codes.Unavailable, err.Error(), + ) + } if handled { return outCtx, conn, nil } diff --git a/subservers/manager.go b/subservers/manager.go index 3fcda911..78da300a 100644 --- a/subservers/manager.go +++ b/subservers/manager.go @@ -153,7 +153,7 @@ func (s *Manager) RegisterRestServices(ctx context.Context, // and if so, the remote connection to that sub-server is returned. The bool // return value indicates if the uri is managed by one of the sub-servers // running in remote mode. -func (s *Manager) GetRemoteConn(uri string) (bool, *grpc.ClientConn) { +func (s *Manager) GetRemoteConn(uri string) (bool, *grpc.ClientConn, error) { s.mu.RLock() defer s.mu.RUnlock() @@ -163,13 +163,18 @@ func (s *Manager) GetRemoteConn(uri string) (bool, *grpc.ClientConn) { } if !ss.Remote() { - return false, nil + return false, nil, nil } - return true, ss.remoteConn + if ss.remoteConn == nil { + return true, nil, fmt.Errorf("not yet connected to "+ + "remote sub-server(%s)", ss.Name()) + } + + return true, ss.remoteConn, nil } - return false, nil + return false, nil, nil } // ValidateMacaroon checks if any of the manager's sub-servers owns the given