Search code examples
elasticsearchnest

elasticsearch fails VerifyRepositoryRequest in C# Nest client


After updating to elasticsearch 7.5.1 following code is now causing an exception "Entry point not found"

//old code worked just fine
    var verifyRepositoryResponse = this.elasticClient.VerifyRepository(new VerifyRepositoryRequest("C__MYFOLDER_Backup"));

//new code throws

    var verifyRepositoryResponse = this.elasticClient.Snapshot.VerifyRepository(new VerifyRepositoryRequest("C__MYFOLDER_Backup"));

Note that making following request via fiddler

POST http://localhost:9200/_snapshot/C__MYFOLDER_Backup/_verify HTTP/1.1
User-Agent: Fiddler
Host: localhost:9200
Content-Type: application/json
Content-Length: 0

returns

{"nodes":{"1cWG9trDRi--6I-46lOlBw":{"name":"DESKTOP-5L01F6I"}}}

any ideas what causes the problem here? Unfortunately there is zero documentation on that matter.

UPDATE: Calling the code with a non existing directory as argument

var verifyRepositoryResponse = this.elasticClient.Snapshot.VerifyRepository(new VerifyRepositoryRequest("C__DOESNOTEXIST_Backup"));

I will get a 4xx response as expected in this scenario. Before all tests, repositories and db have been cleaned.

Update: Adavanced error information:

"# FailureReason: Unrecoverable/Unexpected BadResponse while attempting POST on http://localhost:9200/_snapshot/C__MYFOLDER_Backup/_verify\r\n - [1] BadResponse: Node: http://localhost:9200/ Exception: EntryPointNotFoundException Took: 00:00:00.1859931\r\n# Audit 
exception in step 1 BadResponse:\r\nSystem.EntryPointNotFoundException: Entry point was not found.\r\n   at Elasticsearch.Net.Utf8Json.IJsonFormatter`1.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)\r\n   at Deserialize(Object[] , 
JsonReader& , IJsonFormatterResolver )\r\n   at Elasticsearch.Net.Utf8Json.JsonSerializer.Deserialize[T](Byte[] bytes, Int32 offset, IJsonFormatterResolver resolver)\r\n   at Elasticsearch.Net.Utf8Json.JsonSerializer.Deserialize[T](Stream stream, 
IJsonFormatterResolver resolver)\r\n   at Elasticsearch.Net.DiagnosticsSerializerProxy.Deserialize[T](Stream stream)\r\n   at Elasticsearch.Net.ResponseBuilder.SetBody[TResponse](ApiCallDetails details, RequestData requestData, Stream responseStream, String 
mimeType)\r\n   at Elasticsearch.Net.ResponseBuilder.ToResponse[TResponse](RequestData requestData, Exception ex, Nullable`1 statusCode, IEnumerable`1 warnings, Stream responseStream, String mimeType)\r\n   at 
Elasticsearch.Net.HttpWebRequestConnection.Request[TResponse](RequestData requestData)\r\n   at Elasticsearch.Net.RequestPipeline.CallElasticsearch[TResponse](RequestData requestData)\r\n   at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, 
String path, PostData data, IRequestParameters requestParameters)\r\n# Inner Exception: Entry point was not found.\r\nSystem.EntryPointNotFoundException: Entry point was not found.\r\n   at Elasticsearch.Net.Utf8Json.IJsonFormatter`1.Deserialize(JsonReader& 
reader, IJsonFormatterResolver formatterResolver)\r\n   at Deserialize(Object[] , JsonReader& , IJsonFormatterResolver )\r\n   at Elasticsearch.Net.Utf8Json.JsonSerializer.Deserialize[T](Byte[] bytes, Int32 offset, IJsonFormatterResolver resolver)\r\n   at 
Elasticsearch.Net.Utf8Json.JsonSerializer.Deserialize[T](Stream stream, IJsonFormatterResolver resolver)\r\n   at Elasticsearch.Net.DiagnosticsSerializerProxy.Deserialize[T](Stream stream)\r\n   at 
Elasticsearch.Net.ResponseBuilder.SetBody[TResponse](ApiCallDetails details, RequestData requestData, Stream responseStream, String mimeType)\r\n   at Elasticsearch.Net.ResponseBuilder.ToResponse[TResponse](RequestData requestData, Exception ex, Nullable`1 
statusCode, IEnumerable`1 warnings, Stream responseStream, String mimeType)\r\n   at Elasticsearch.Net.HttpWebRequestConnection.Request[TResponse](RequestData requestData)\r\n   at Elasticsearch.Net.RequestPipeline.CallElasticsearch[TResponse](RequestData 
requestData)\r\n   at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)\r\n# Exception:\r\nElasticsearch.Net.UnexpectedElasticsearchClientException: Entry point was not found. ---> 
System.EntryPointNotFoundException: Entry point was not found.\r\n   at Elasticsearch.Net.Utf8Json.IJsonFormatter`1.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)\r\n   at Deserialize(Object[] , JsonReader& , IJsonFormatterResolver 
)\r\n   at Elasticsearch.Net.Utf8Json.JsonSerializer.Deserialize[T](Byte[] bytes, Int32 offset, IJsonFormatterResolver resolver)\r\n   at Elasticsearch.Net.Utf8Json.JsonSerializer.Deserialize[T](Stream stream, IJsonFormatterResolver resolver)\r\n   at 
Elasticsearch.Net.DiagnosticsSerializerProxy.Deserialize[T](Stream stream)\r\n   at Elasticsearch.Net.ResponseBuilder.SetBody[TResponse](ApiCallDetails details, RequestData requestData, Stream responseStream, String mimeType)\r\n   at 
Elasticsearch.Net.ResponseBuilder.ToResponse[TResponse](RequestData requestData, Exception ex, Nullable`1 statusCode, IEnumerable`1 warnings, Stream responseStream, String mimeType)\r\n   at Elasticsearch.Net.HttpWebRequestConnection.Request[TResponse](RequestData 
requestData)\r\n   at Elasticsearch.Net.RequestPipeline.CallElasticsearch[TResponse](RequestData requestData)\r\n   at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)\r\n   --- 
End of inner exception stack trace ---\r\n   at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)\r\n   at 
Nest.Specification.SnapshotApi.SnapshotNamespace.VerifyRepository(IVerifyRepositoryRequest request)\r\n   at InforsHT.Genesis.Infrastructure.Data.Repositories.ElasticBackupAndRestoreProxy.IsBackupLocationPresent(String backupLocation) in 
C:\\work\\eve\\Source\\InforsHT.Genesis.Infrastructure.Data\\Repositories\\ElasticBackupAndRestoreProxy.cs:line 44\r\n"

Solution

  • This is a bug. VerifyRepositoryResponse's Node property is attributed with a JsonFormatterAttribute that expects to deserialize an IDictionary<string, CompactNodeInfo> when the property type is IReadOnlyDictionary<string, CompactNodeInfo>. This is problematic for the underlying JSON serializer which uses strongly typed formatters, IJsonFormatter<T>, where the type T must match exactly.

    I've opened an issue to track and a pull request to fix the issue. For now, you'd be able to workaround the bug by using the low level client exposed on the high level client

    var response = client.LowLevel.Snapshot.VerifyRepository<DynamicResponse>("C__MYFOLDER_Backup");
    

    and traverse DynamicResponse. Alternatively, use StringResponse and parse using JObject or JsonDocument and traverse.