Skip to content

Unobserved exception in bulk all #8634

@yfital

Description

@yfital

NEST/Elasticsearch.Net version:
7.17.5

Elasticsearch version:
Irrelevant (happens in unit tests as well)

.NET runtime version:
9

Operating system version:
Win11

Description of the problem including expected versus actual behavior:
A clear and concise description of what the bug is.
In case an exception arrives while running a BulkAll, although the exception is propegated towards the observable's on error, the interal implementatio of nest's ForEachAsync also throws the exception (after calling the "done" method).

As such, an unobserved exception will trigger even if the actual exception is touched by OnException overload.

Steps to reproduce:

  1. Create a dummy in-memory response which returns a >500 error code.
  2. Call BulkAll
  3. Subscribe on said bulk all observable, use the exception
  4. Add a fictive long delay to allow GC to run, notice unobserved

Expected behavior
A clear and concise description of what you expected to happen.
No unobserved excpetion when actual exception is being treated.

Provide ConnectionSettings (if relevant):

Provide DebugInformation (if relevant):

Sample code:

var tsc = new TaskCompletionSource<bool>(ct, TaskCreationOptions.RunContinuationsAsynchronously);

            var bulkAllObservable = Client.BulkAll(data, b => b.Index(indexName), ct);
            using (bulkAllObservable.Subscribe(
                       _ => { },
                       exp =>
                       {
                           tsc.SetException(exp);
                       },
                       () => { tsc.SetResult(true); }))
            {
                await tsc.Task;
            }

Suspected code issue:

		catch (Exception obj)
		{
			done(obj);
			throw;
		}

In ForEachAsync method, notice that the actual throw is never catched in any flow (latest vesrions as well).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions