Skip to content

[BUG] NullReferenceException being thrown with elasticsearch c# client 8.18.3 reference Agent.Tracer with unreachable server url (dns failure) #2622

@bhanvexcelco

Description

@bhanvexcelco

APM Agent version

The version of the Elastic.Apm nuget package used
1.32..2
1.31.0

Environment

elasticsearch dotnet client 8.18.3

Operating system and version:
windows 11

.NET Framework/Core name and version (e.g. .NET 4.6.2, NET Core 3.1.100) :
.NET 8
Microsoft.AspNetCore.App 8.0.15

Application Target Framework(s) (e.g. net462, netcoreapp3.1):

Describe the bug

A clear and concise description of what the bug is.

I also logged a bug in elasticsearch c# client repo as this issue could be involved with APM and elasticsearch client: elastic/elasticsearch-net#8624

With a reference to Agent.Tracer, The latest elasticearch client 8 client.PingAsync(...) throws NullReferenceException when the server url is unreachable (simulation of dns failure)

Note: elasticsearch c# client 9.0.5 does not have this issue. any version below 9.0.5 (all 8.x) throws null reference exception

To Reproduce

Steps to reproduce the behavior:

using Elastic.Apm;
using Elastic.Clients.Elasticsearch;
using Elastic.Transport;

Console.WriteLine("Begin Testing.");

var user = "elasticuser";
var pwd = "randomepwd";

//NOTE: provide unreachable url to simulate DNS failure
var searchUris = new Uri[] { new Uri("https://localhost2:9200") };

var pool = new StaticNodePool(searchUris);

//var clientSettings = new ElasticsearchClientSettings(pool);
var clientSettings = new ElasticsearchClientSettings(pool);
clientSettings.ServerCertificateValidationCallback((o, cert, chain, errors) => true)
.DefaultFieldNameInferrer(name => name)
.DefaultDisableIdInference()
.EnableDebugMode()
.Authentication(new BasicAuthentication(user, pwd));

var client = new ElasticsearchClient(clientSettings);

// NOTE: below line caused NullReferenceException being thrown with Elastic.Apm 1.32.2 or 1.31.0
// and elastic client 8.17.4 or 8.18.3, 9.0.3, 9.0.4
// Working fine with elasti client 9.0.5, 9.0.6, 9.0.7
var tracer = Agent.Tracer;
var pingResponse = await client.PingAsync().ConfigureAwait(false);

Console.WriteLine($"Is valid response: {pingResponse.IsValidResponse}");

Expected behavior

pingResponse returned and IsValidResponse should be set to false

Actual behavior

NullReferenceException being thrown

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions