Skip to content

Commit ba3193b

Browse files
committed
rpc_proxy+subservers: error out of GetRemoteConn if not ready
Due to the rpcProxy being started early now, it could be the case that a call is made to `GetRemoteConn` before the remote connection has actually been set up. This commit catches this case so that an error can be returned and a panic avoided.
1 parent 2a825f1 commit ba3193b

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

rpc_proxy.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,12 @@ func (p *rpcProxy) makeDirector(allowLitRPC bool) func(ctx context.Context,
304304
// since it must either be an lnd call or something that'll be
305305
// handled by the integrated daemons that are hooking into lnd's
306306
// gRPC server.
307-
handled, conn := p.subServerMgr.GetRemoteConn(requestURI)
307+
handled, conn, err := p.subServerMgr.GetRemoteConn(requestURI)
308+
if err != nil {
309+
return outCtx, nil, status.Errorf(
310+
codes.Unavailable, err.Error(),
311+
)
312+
}
308313
if handled {
309314
return outCtx, conn, nil
310315
}

subservers/manager.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (s *Manager) RegisterRestServices(ctx context.Context,
153153
// and if so, the remote connection to that sub-server is returned. The bool
154154
// return value indicates if the uri is managed by one of the sub-servers
155155
// running in remote mode.
156-
func (s *Manager) GetRemoteConn(uri string) (bool, *grpc.ClientConn) {
156+
func (s *Manager) GetRemoteConn(uri string) (bool, *grpc.ClientConn, error) {
157157
s.mu.RLock()
158158
defer s.mu.RUnlock()
159159

@@ -163,13 +163,18 @@ func (s *Manager) GetRemoteConn(uri string) (bool, *grpc.ClientConn) {
163163
}
164164

165165
if !ss.Remote() {
166-
return false, nil
166+
return false, nil, nil
167+
}
168+
169+
if ss.remoteConn == nil {
170+
return true, nil, fmt.Errorf("not yet connected to "+
171+
"remote sub-server(%s)", ss.Name())
167172
}
168173

169-
return true, ss.remoteConn
174+
return true, ss.remoteConn, nil
170175
}
171176

172-
return false, nil
177+
return false, nil, nil
173178
}
174179

175180
// ValidateMacaroon checks if any of the manager's sub-servers owns the given

0 commit comments

Comments
 (0)