Description
We are migrating to NEST 2.0. One of our applications tries to migrate existing data from relational DB to ES using Bulk operations. It worked fine with NEST 1.7. After the migration, when executing it, after importing many documents, I saw a strange exception. I will paste below the part of the stack that belongs to NEST
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Elasticsearch.Net.ExceptionExtensions.RethrowKeepingStackTrace(Exception exception)
at Elasticsearch.Net.RequestPipeline.CallElasticsearch[TReturn](RequestData requestData)
at Elasticsearch.Net.Transport`1.Request[TReturn](HttpMethod method, String path, PostData`1 data, IRequestParameters requestParameters)
at Elasticsearch.Net.ElasticLowLevelClient.DoRequest[T](HttpMethod method, String path, PostData`1 data, IRequestParameters requestParameters)
at Elasticsearch.Net.ElasticLowLevelClient.Bulk[T](PostData`1 body, Func`2 requestParameters)
at Nest.LowLevelDispatch.BulkDispatch[T](IRequest`1 p, PostData`1 body)
at Nest.ElasticClient.Nest.IHighLevelToLowLevelDispatcher.Dispatch[TRequest,TQueryString,TResponse](TRequest request, Func`3 responseGenerator, Func`3 dispatch)
at Nest.ElasticClient.Nest.IHighLevelToLowLevelDispatcher.Dispatch[TRequest,TQueryString,TResponse](TRequest request, Func`3 dispatch)
at Nest.ElasticClient.Bulk(IBulkRequest request)
Then I dived into NEST code to check that RethrowKeepingStackTrace method... And honestly, I don't know the purpose of that method. I mean. It is being called in 4 places in all the codebase:
- RequestPipeline.CallElasticSearch
- RequestPipeline.CallElasticSearchAsync
- Transport.Ping
- Transport.PingAsync
In all of those cases it is being called from within a catch block. From what I get, this tries to rethrow the exception without losing the stack trace. Wouldn't it be preferable to simply call
throw;
As far as I know, that is the preferred way of rethrowing an exception from within a catch block.