BulkWriteAsync does not interrupt when CancellationToken gets canceled

I am using the latest version of the C# Mongo Driver with a v4.2 database. When I call BulkWriteAsync (http://mongodb.github.io/mongo-csharp-driver/2.10/apidocs/html/M_MongoDB_Driver_IMongoCollection_1_BulkWriteAsync.htm) with a CancellationToken, if the cancellation token gets cancelled while the BulkWriteAsync is running, no OperationCanceledException gets thrown. This is a problem because the transaction can take a long time making the database hold a lot of locks and interfere with other requests. I need to interrupt any database commands as soon as the cancellation token cancels to reduce the risk of deadlocks caused by transactions continuing to run for too long.

Hi @Alejandro_Carrazzoni, welcome!

Could you provide a minimal reproducible code snippet to reproduce the behaviour that you’re seeing ?


I hit the same problem with Aggregate.
I think the root cause is this issue:
The issue was created Mar 20 2015 and is still unresolved