You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unfortunately Microsoft.Data.SqlClient in version 5.0.1 has a severe memory leak, which also leads to leaking memory using RepoDb.SqlServer v1.13.0.
Details: Issue #1810 on SqlClient Github repo
usingSystem.Diagnostics;usingSystem.Threading;usingSystem.Threading.Tasks;usingMicrosoft.Data.SqlClient;usingMicrosoft.Extensions.Configuration;usingMicrosoft.Extensions.Hosting;usingRepoDb;publicclassMemLeakingService:BackgroundService{privatereadonlystringconnectionString;publicMemLeakingService(IConfigurationconfiguration){this.connectionString=configuration.GetConnectionString("Database");}protectedoverrideasyncTaskExecuteAsync(CancellationTokentoken){Console.WriteLine($"SqlClient version: {FileVersionInfo.GetVersionInfo(typeof(SqlCommand).Assembly.Location).ProductVersion}");while(true){conststringsql="SELECT n FROM (VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) v(n)";using(varsqlConnection=newSqlConnection(this.connectionString)){awaitsqlConnection.ExecuteQueryAsync(sql,cancellationToken:token).ConfigureAwait(false);}GC.Collect();// for demonstration only; removing this line does not change outputConsole.WriteLine($"Lost registrations: {CountLostSqlCommands(token)}");}}staticintCountLostSqlCommands(CancellationTokentoken){varcts=(CancellationTokenSource)typeof(CancellationToken).GetField("_source",System.Reflection.BindingFlags.Instance|System.Reflection.BindingFlags.NonPublic)!.GetValue(token)!;varregistrationsField=typeof(CancellationTokenSource).GetField("_registrations",System.Reflection.BindingFlags.Instance|System.Reflection.BindingFlags.NonPublic)!;varregistrations=registrationsField.GetValue(cts);if(registrations==null)return0;varcallbacksProperty=registrationsField.FieldType.GetField("Callbacks",System.Reflection.BindingFlags.Instance|System.Reflection.BindingFlags.Public)!;varcallbackNode=callbacksProperty.GetValue(registrations);varcallbackNodeType=callbacksProperty.FieldType;varnextProperty=callbackNodeType.GetField("Next",System.Reflection.BindingFlags.Instance|System.Reflection.BindingFlags.Public)!;varstateProperty=callbackNodeType.GetField("CallbackState",System.Reflection.BindingFlags.Instance|System.Reflection.BindingFlags.Public)!;intlostSqlCommands=0;while(callbackNode!=null){varcallbackState=stateProperty.GetValue(callbackNode);if(typeof(SqlCommand)==callbackState?.GetType()){lostSqlCommands+=1;}callbackNode=nextProperty.GetValue(callbackNode);}returnlostSqlCommands;}}
Resolution
Update Microsoft.Data.SqlClient to 5.1.0 as soon as the preview version is marked as stable (should be soon)
Library Version:
RepoDb v1.13.0 and RepoDb.SqlServer v1.13.0
The text was updated successfully, but these errors were encountered:
Bug Description
Unfortunately Microsoft.Data.SqlClient in version 5.0.1 has a severe memory leak, which also leads to leaking memory using RepoDb.SqlServer v1.13.0.
Details: Issue #1810 on SqlClient Github repo
Reproduction Steps
Use RepoDb Async calls in a periodic background service adapted from code example dotnet/SqlClient#1810 (comment)
Resolution
Update Microsoft.Data.SqlClient to 5.1.0 as soon as the preview version is marked as stable (should be soon)
Library Version:
RepoDb v1.13.0 and RepoDb.SqlServer v1.13.0
The text was updated successfully, but these errors were encountered: