[CSHARP-3219] Add a reason for ConnectionClosedEvent Created: 07/Oct/20  Updated: 14/Nov/22

Status: Backlog
Project: C# Driver
Component/s: Connectivity
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor - P4
Reporter: Dmitry Lukyanov (Inactive) Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Previously we didn't add a reason field into ConnectionClosedEvent because this event is called from Dispose method and we didn't have a way to determine for what reason this method has been called.

But as we found in the scope of https://jira.mongodb.org/browse/HELP-18973, this value can be helpful for some connectivity investigations.

Two options which were discussed in the slack:

  1. Add a new Close(ConnectionClosedReason reason) method which will contain triggering event logic and Dispose logic. The disadvantage of this way (additionally to having Close and Dispose methods for the same class) is that it's unclear whether Dispose method should still have triggering events or no. If yes, we still can potentially have the same issue with empty reason field as we have now, if no - then we can have the potential situation without ConnectionClosedEvent at all.
  2. Investigate how this logic works in java. As far as I can see they trigger the ConnectionClosedEvent before calling stream.Close (afaik, this is an equivalent of stream.Dispose in c#): https://github.com/mongodb/mongo-java-driver/blob/91e670f86303121c7afe68145d3ca5d341079506/driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java#L598 

Generated at Wed Feb 07 21:44:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.