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.
This commit is contained in:
Elle Mouton 2023-05-03 10:26:11 +02:00
parent 2a825f1009
commit ba3193b341
No known key found for this signature in database
GPG key ID: D7D916376026F177
2 changed files with 15 additions and 5 deletions

View file

@ -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