Cannot access a disposed object.\nObject name: 'System.Net.Sockets.Socket
See original GitHub issueHi Team, I am using EF core 3.1.19 to connect to AWS RDS MYSQL database. The packages used are below .
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.19" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.19" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.19" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.19" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.7" />
and MYSQL Connector
used is 0.69.10 version
I am getting the below exception intermittently while doing some db operation . The inner exception states that Cannot access a disposed object.\nObject name: 'System.Net.Sockets.Socket
I recently migrated from EF core 2.7 which was working fine there.
Exception Details
Message": "Connect Timeout expired.",
"Source": "MySqlConnector",
"StackTraceString": " at MySqlConnector.Core.ServerSession.OpenTcpSocketAsync(ConnectionSettings cs, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken)\n at MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, Int32 startTickCount, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ServerSession.cs:line 368\n at MySqlConnector.Core.ConnectionPool.GetSessionAsync(MySqlConnection connection, Int32 startTickCount, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ConnectionPool.cs:line 143\n at MySqlConnector.Core.ConnectionPool.GetSessionAsync(MySqlConnection connection, Int32 startTickCount, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ConnectionPool.cs:line 143\n at MySql.Data.MySqlClient.MySqlConnection.CreateSessionAsync(ConnectionPool pool, Int32 startTickCount, Nullable`1 ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySql.Data.MySqlClient/MySqlConnection.cs:line 758",
"RemoteStackTraceString": null,
"RemoteStackIndex": 0,
"HResult": -2147467259,
"HelpURL": null
},
{
"Depth": 4,
"ClassName": "System.ObjectDisposedException",
"Message": "Cannot access a disposed object.\nObject name: 'System.Net.Sockets.Socket'.",
"Source": "System.Net.Sockets",
"StackTraceString": " at System.Net.Sockets.Socket.BeginConnect(IPAddress address, Int32 port, AsyncCallback requestCallback, Object state)\n at System.Net.Sockets.TcpClient.BeginConnect(IPAddress address, Int32 port, AsyncCallback requestCallback, Object state)\n at System.Threading.Tasks.TaskFactory`1.FromAsyncImpl[TArg1,TArg2](Func`5 beginMethod, Func`2 endFunction, Action`1 endAction, TArg1 arg1, TArg2 arg2, Object state, TaskCreationOptions creationOptions)\n at System.Net.Sockets.TcpClient.ConnectAsync(IPAddress address, Int32 port)\n at MySqlConnector.Core.ServerSession.OpenTcpSocketAsync(ConnectionSettings cs, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ServerSession.cs:line 907",
Further technical details
MySQL version: 5.7.33 Operating system: Linux 64 AWS ECS Pomelo.EntityFrameworkCore.MySql version:3.2.7 Microsoft.AspNetCore.App vesion: 3.1
Other details about my project setup: connection string Server=serverurl;Port=3306;Database=DBName;User=;Password=**;Allow User Variables=True;SslMode=Required
i am registering the DB context as InstancePerLifetimeScope.
Please help me on this.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9
FWIW the Inner Exception was removed in https://github.com/mysql-net/MySqlConnector/issues/1035 (>= 1.3.13) to avoid the confusing error message in the OP.
Yes @lauxjpn , Each concurrent jobs will be running on separate thread and all db operation will happen under a lifetimescope instance created for each job like below
and dbcontext is resistered as
builder.Register({dbconext}).InstancePerLifetimeScope();
let me check the number of open connections