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

Pavel Tupitsyn updated IGNITE-14776:
------------------------------------
    Release Note: .NET: Fixed NullReferenceException in thin client due to late 
logger setter
     Description: 
Because the logger is set last inside of the 
{code:c#}ClientFailoverSocket{code} class, if there are issues with the 
{code:c#}GetIpEndpoints{code} call, an argument exception can occur when a 
debug message is logged inside of {code:c#}GetIps{code} when the ip address 
can't be parsed.  In my case, this occurred with a DNS failure.

Stack Trace:
{code:c#}
 System.ArgumentNullException: Value cannot be null. (Parameter 'logger')
 at Apache.Ignite.Core.Impl.Common.IgniteArgumentCheck.NotNull(Object arg, 
String argName)
 at Apache.Ignite.Core.Log.LoggerExtensions.Log(ILogger logger, LogLevel level, 
Exception ex, String message)
 at Apache.Ignite.Core.Log.LoggerExtensions.Debug(ILogger logger, Exception ex, 
String message)
 at Apache.Ignite.Core.Impl.Client.ClientFailoverSocket.GetIps(String host, 
Boolean suppressExceptions)
 at 
Apache.Ignite.Core.Impl.Client.ClientFailoverSocket.<GetIpEndPoints>d__11.MoveNext()
 at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
 at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
 at 
Apache.Ignite.Core.Impl.Client.ClientFailoverSocket..ctor(IgniteClientConfiguration
 config, Marshaller marsh, TransactionsClient transactions)
 at Apache.Ignite.Core.Impl.Client.IgniteClient..ctor(IgniteClientConfiguration 
clientConfiguration)
 at Apache.Ignite.Core.Ignition.StartClient(IgniteClientConfiguration 
clientConfiguration)
{code}

Here's the constructor code:
{code:c#}
            Debug.Assert(config != null);
            Debug.Assert(marsh != null);
            Debug.Assert(transactions != null);

            _config = config;
            _marsh = marsh;
            _transactions = transactions;

#pragma warning disable 618 // Type or member is obsolete
            if (config.Host == null && (config.Endpoints == null || 
config.Endpoints.Count == 0))
            {
                throw new IgniteClientException("Invalid 
IgniteClientConfiguration: Host is null, " +
                                                "Endpoints is null or empty. 
Nowhere to connect.");
            }
#pragma warning restore 618

            _endPoints = GetIpEndPoints(config).ToList();

            if (_endPoints.Count == 0)
            {
                throw new IgniteClientException("Failed to resolve all 
specified hosts.");
            }

            _logger = (_config.Logger ?? 
NoopLogger.Instance).GetLogger(GetType());

            ConnectDefaultSocket();
            OnFirstConnection();
{code}

Note how the _logger variable isn't set until the very end of the constructor.

  was:

Because the logger is set last inside of the 
{code:c#}ClientFailoverSocket{code} class, if there are issues with the 
{code:c#}GetIpEndpoints{code} call, an argument exception can occur when a 
debug message is logged inside of {code:c#}GetIps{code} when the ip address 
can't be parsed.  In my case, this occurred with a DNS failure.

Stack Trace:
{code:c#}
 System.ArgumentNullException: Value cannot be null. (Parameter 'logger')
 at Apache.Ignite.Core.Impl.Common.IgniteArgumentCheck.NotNull(Object arg, 
String argName)
 at Apache.Ignite.Core.Log.LoggerExtensions.Log(ILogger logger, LogLevel level, 
Exception ex, String message)
 at Apache.Ignite.Core.Log.LoggerExtensions.Debug(ILogger logger, Exception ex, 
String message)
 at Apache.Ignite.Core.Impl.Client.ClientFailoverSocket.GetIps(String host, 
Boolean suppressExceptions)
 at 
Apache.Ignite.Core.Impl.Client.ClientFailoverSocket.<GetIpEndPoints>d__11.MoveNext()
 at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
 at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
 at 
Apache.Ignite.Core.Impl.Client.ClientFailoverSocket..ctor(IgniteClientConfiguration
 config, Marshaller marsh, TransactionsClient transactions)
 at Apache.Ignite.Core.Impl.Client.IgniteClient..ctor(IgniteClientConfiguration 
clientConfiguration)
 at Apache.Ignite.Core.Ignition.StartClient(IgniteClientConfiguration 
clientConfiguration)
{code}

Here's the constructor code:
{code:c#}
            Debug.Assert(config != null);
            Debug.Assert(marsh != null);
            Debug.Assert(transactions != null);

            _config = config;
            _marsh = marsh;
            _transactions = transactions;

#pragma warning disable 618 // Type or member is obsolete
            if (config.Host == null && (config.Endpoints == null || 
config.Endpoints.Count == 0))
            {
                throw new IgniteClientException("Invalid 
IgniteClientConfiguration: Host is null, " +
                                                "Endpoints is null or empty. 
Nowhere to connect.");
            }
#pragma warning restore 618

            _endPoints = GetIpEndPoints(config).ToList();

            if (_endPoints.Count == 0)
            {
                throw new IgniteClientException("Failed to resolve all 
specified hosts.");
            }

            _logger = (_config.Logger ?? 
NoopLogger.Instance).GetLogger(GetType());

            ConnectDefaultSocket();
            OnFirstConnection();
{code}

Note how the _logger variable isn't set until the very end of the constructor.


> .NET: ClientFailoverSocket sets logger too late, resulting in null loggers 
> downstream
> -------------------------------------------------------------------------------------
>
>                 Key: IGNITE-14776
>                 URL: https://issues.apache.org/jira/browse/IGNITE-14776
>             Project: Ignite
>          Issue Type: Bug
>          Components: clients, platforms
>    Affects Versions: 2.10, 2.11
>            Reporter: Robert May
>            Assignee: Pavel Tupitsyn
>            Priority: Critical
>              Labels: .NET
>             Fix For: 2.12
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Because the logger is set last inside of the 
> {code:c#}ClientFailoverSocket{code} class, if there are issues with the 
> {code:c#}GetIpEndpoints{code} call, an argument exception can occur when a 
> debug message is logged inside of {code:c#}GetIps{code} when the ip address 
> can't be parsed.  In my case, this occurred with a DNS failure.
> Stack Trace:
> {code:c#}
>  System.ArgumentNullException: Value cannot be null. (Parameter 'logger')
>  at Apache.Ignite.Core.Impl.Common.IgniteArgumentCheck.NotNull(Object arg, 
> String argName)
>  at Apache.Ignite.Core.Log.LoggerExtensions.Log(ILogger logger, LogLevel 
> level, Exception ex, String message)
>  at Apache.Ignite.Core.Log.LoggerExtensions.Debug(ILogger logger, Exception 
> ex, String message)
>  at Apache.Ignite.Core.Impl.Client.ClientFailoverSocket.GetIps(String host, 
> Boolean suppressExceptions)
>  at 
> Apache.Ignite.Core.Impl.Client.ClientFailoverSocket.<GetIpEndPoints>d__11.MoveNext()
>  at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
>  at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
>  at 
> Apache.Ignite.Core.Impl.Client.ClientFailoverSocket..ctor(IgniteClientConfiguration
>  config, Marshaller marsh, TransactionsClient transactions)
>  at 
> Apache.Ignite.Core.Impl.Client.IgniteClient..ctor(IgniteClientConfiguration 
> clientConfiguration)
>  at Apache.Ignite.Core.Ignition.StartClient(IgniteClientConfiguration 
> clientConfiguration)
> {code}
> Here's the constructor code:
> {code:c#}
>             Debug.Assert(config != null);
>             Debug.Assert(marsh != null);
>             Debug.Assert(transactions != null);
>             _config = config;
>             _marsh = marsh;
>             _transactions = transactions;
> #pragma warning disable 618 // Type or member is obsolete
>             if (config.Host == null && (config.Endpoints == null || 
> config.Endpoints.Count == 0))
>             {
>                 throw new IgniteClientException("Invalid 
> IgniteClientConfiguration: Host is null, " +
>                                                 "Endpoints is null or empty. 
> Nowhere to connect.");
>             }
> #pragma warning restore 618
>             _endPoints = GetIpEndPoints(config).ToList();
>             if (_endPoints.Count == 0)
>             {
>                 throw new IgniteClientException("Failed to resolve all 
> specified hosts.");
>             }
>             _logger = (_config.Logger ?? 
> NoopLogger.Instance).GetLogger(GetType());
>             ConnectDefaultSocket();
>             OnFirstConnection();
> {code}
> Note how the _logger variable isn't set until the very end of the constructor.



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

Reply via email to