[ 
https://issues.apache.org/jira/browse/CAMEL-16526?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Dietrich Schulten updated CAMEL-16526:
--------------------------------------
    Description: 
When {{com.orbitz.consul.AgentClient}} cannot ping Consul in its {{ping()}} 
method during client creation, no exception is thrown in the exception handler 
of {{Suppliers.memorize}} defined in the {{ConsulServiceDiscovery}} ctor, 
rather the exception only gets wrapped and then nothing is done with it:
{code:java}
this.client = Suppliers.memorize(() -> 
configuration.createConsulClient(getCamelContext()),
        e -> RuntimeCamelException.wrapRuntimeCamelException(e)); {code}
That has the consequence that {{ConsulServiceDiscovery.getServices}} throws a 
NPE, which in turn kills the loop early in {{CombinedServiceDiscovery}} where 
all service discoveries are being asked for their services list.

The {{client}} supplier function gets called lazily when {{getServices}} is 
invoked, it supplies  {{null}} because the exception is ignored and then a NPE 
occurs after {{client.get()}}:
{code:java}
@Override
public List<ServiceDefinition> getServices(String name) {
    List<CatalogService> services = client.get() // null
      .catalogClient().getService(name, queryOptions).getResponse();
    .... {code}

The wrapped exception should get thrown and caught with a warning in 
{{getServices}} or {{CombinedServiceDiscovery}} should be prepared for service 
discoveries that throw exceptions, log warnings and continue to ask other 
discoveries.

  was:
When {{com.orbitz.consul.AgentClient}} cannot ping Consul in its {{ping()}} 
method during client creation, no exception is thrown in the exception handler 
of {{Suppliers.memorize}} defined in the {{ConsulServiceDiscovery}} ctor, 
rather the exception only gets wrapped and then nothing is done with it:
{code:java}
this.client = Suppliers.memorize(() -> 
configuration.createConsulClient(getCamelContext()),
        e -> RuntimeCamelException.wrapRuntimeCamelException(e)); {code}
That has the consequence that {{ConsulServiceDiscovery.getServices}} throws a 
NPE, which in turn kills the loop early in {{CombinedServiceDiscovery}} where 
all service discoveries are being asked for their services list.

The {{client}} supplier function gets called lazily when {{getServices}} is 
invoked, it supplies  {{null}} because the exception is ignored and then a NPE 
occurs after {{client.get()}}:
{code:java}
@Override
public List<ServiceDefinition> getServices(String name) {
    List<CatalogService> services = client.get() // null
      .catalogClient().getService(name, queryOptions).getResponse();
    .... {code}

The wrapped exception should get thrown and {{CombinedServiceDiscovery}} should 
be prepared for service discoveries that throw exceptions, log warnings and 
continue to ask other discoveries.


> Unreachable consul leads to NPE in CombinedServiceDiscovery
> -----------------------------------------------------------
>
>                 Key: CAMEL-16526
>                 URL: https://issues.apache.org/jira/browse/CAMEL-16526
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-core
>    Affects Versions: 3.9.0
>            Reporter: Dietrich Schulten
>            Priority: Major
>
> When {{com.orbitz.consul.AgentClient}} cannot ping Consul in its {{ping()}} 
> method during client creation, no exception is thrown in the exception 
> handler of {{Suppliers.memorize}} defined in the {{ConsulServiceDiscovery}} 
> ctor, rather the exception only gets wrapped and then nothing is done with it:
> {code:java}
> this.client = Suppliers.memorize(() -> 
> configuration.createConsulClient(getCamelContext()),
>         e -> RuntimeCamelException.wrapRuntimeCamelException(e)); {code}
> That has the consequence that {{ConsulServiceDiscovery.getServices}} throws a 
> NPE, which in turn kills the loop early in {{CombinedServiceDiscovery}} where 
> all service discoveries are being asked for their services list.
> The {{client}} supplier function gets called lazily when {{getServices}} is 
> invoked, it supplies  {{null}} because the exception is ignored and then a 
> NPE occurs after {{client.get()}}:
> {code:java}
> @Override
> public List<ServiceDefinition> getServices(String name) {
>     List<CatalogService> services = client.get() // null
>       .catalogClient().getService(name, queryOptions).getResponse();
>     .... {code}
> The wrapped exception should get thrown and caught with a warning in 
> {{getServices}} or {{CombinedServiceDiscovery}} should be prepared for 
> service discoveries that throw exceptions, log warnings and continue to ask 
> other discoveries.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to