Skip to content

fix: resolve memory leaks from missing IDisposable implementations and undisposed resources#105

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/analyze-memory-leak-code
Draft

fix: resolve memory leaks from missing IDisposable implementations and undisposed resources#105
Copilot wants to merge 3 commits intomasterfrom
copilot/analyze-memory-leak-code

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 12, 2026

Audit of disposable resource handling found 6 leak sites — undisposed SemaphoreSlim, DbConnection, and Azure ServiceBus resources.

Critical

  • DbDataReaderAsyncEnumerator2DbConnection from factory was assigned to a local in MoveNextAsync() and never disposed. Stored as field; disposed in DisposeAsync(). Compare with DbDataReaderAsyncEnumerator which already did this correctly.
// Before: connection leaked
var dbConnection = await _dbConnectionFactory(_cancellationToken);

// After: stored and disposed
_dbConnection = await _dbConnectionFactory(_cancellationToken);
// ... in DisposeAsync():
if (_dbConnection != null)
    await _dbConnection.DisposeAsync().ConfigureAwait(false);
  • AzureServiceBusQueue — held SemaphoreSlim, ServiceBusClient, ServiceBusSender, ServiceBusReceiver with no IDisposable/IAsyncDisposable. Implemented both.

  • AzureEventHubReceiverQueue — held SemaphoreSlim + EventHubClient with no IDisposable. Implemented.

Medium

  • KafkaReceiverQueue_consumerStartSemaphore.Dispose() missing from Dispose(bool). Sibling classes (KafkaEventStreamConsumer, KafkaSchemaRegistryReceiverQueue) already had this.

  • Memory.SortedSetSemaphoreSlim field, no IDisposable. Implemented.

  • Sql.Mapping.TableSemaphoreSlim field, no IDisposable. Implemented.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits March 12, 2026 21:14
… calls

- DbDataReaderAsyncEnumerator2: store and dispose DbConnection in DisposeAsync
- KafkaReceiverQueue: dispose _consumerStartSemaphore in Dispose
- AzureServiceBusQueue: implement IDisposable to dispose SemaphoreSlim, ServiceBus resources
- AzureEventHubReceiverQueue: implement IDisposable to dispose SemaphoreSlim and EventHubClient
- Memory/SortedSet: implement IDisposable to dispose SemaphoreSlim
- Sql/Mapping/Table: implement IDisposable to dispose SemaphoreSlim

Co-authored-by: sylvester-henrique <19980165+sylvester-henrique@users.noreply.github.com>
…Disposable

Co-authored-by: sylvester-henrique <19980165+sylvester-henrique@users.noreply.github.com>
Copilot AI changed the title [WIP] Analyze code for potential memory leaks fix: resolve memory leaks from missing IDisposable implementations and undisposed resources Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants