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
{{ message }}
Repository navigation
Issues with user locking around connection open/close #1127
Currently, connection open and close operations aren't protected via the user lock. This means that if someone tries to close (or use) a connection while it's still connecting, undefined stuff will occur instead of a clean, predictable connection.
Do this once the open/close logic is cleaned up as part of 3.2's distributed transaction redo.
Once this issue is done, the EFCore provider's Throws_on_concurrent_query_first can be unskipped.
@roji I get what you're saying, but I'm not sure how to do it. I have multiple REST endpoints that could potentially access the same data at the same time. Perhaps my overall setup is wrong, but it was definitely working when my app was running on dotnet core 2.1. I'm trying to migrate to 3.1 (2.1 > 2.2 > 3.0 > 3.1) and as soon as I updated the reference to Npgsql.EntityFrameworkCore.PostgreSQL to a 3+ version I started running into this error.
Where and how do we check to make sure we're not concurrently accessing a connection? I know this is specific to my application, but I also have seen several other issues link to this one and no one seems to be detailing a method for implementing this work around and I'm honestly just completely perplexed.
@engineer-andrew I'm missing a lot of detail, but it sounds like you may be keeping a DbContext on a singleton service. DbContext instances, like connections, are not meant to be shared and can only be used once at a time. Assuming your service is a singleton (since multiple REST endpoints potentially access it at the same time), create a new DbContext each time you want to do a database operation (or more precisely, a unit of work). In general, don't store the instance in some member variable where others can use it - keep it in the stack for your own private us, and dispose it once you don't need anymore.
Hope that helps, if not you're going to have to provide a bit more context on what your application does.
@roji Honestly, I posted my question mostly out of frustration with my problem and was not really expecting an answer. I definitely wasn't expecting an answer within 4 hours. And, of course, your answer sent me in the right direction. I'm using a Unit of Work pattern with a new DbContext created for each request (which is the unit of work). However, in one of my requests I was retrieving data from two repositories asynchronously. I somehow got so focused on the idea that it was the multiple requests coming into the API simultaneously that I was unable to see what was really causing the problem.
Thank you so much for getting back to me so quickly. I appreciate the help on this question and the overall work you're doing on this tool.
Activity
roji commentedon Nov 12, 2016
SO: http://stackoverflow.com/questions/40530520/npoco-query-with-npgsql-reset-called-on-connector-with-state-executing
Procee commentedon Jun 29, 2019
Is there some kind of work around for this?
1 remaining item
engineer-andrew commentedon Apr 20, 2020
@roji I get what you're saying, but I'm not sure how to do it. I have multiple REST endpoints that could potentially access the same data at the same time. Perhaps my overall setup is wrong, but it was definitely working when my app was running on dotnet core 2.1. I'm trying to migrate to 3.1 (2.1 > 2.2 > 3.0 > 3.1) and as soon as I updated the reference to Npgsql.EntityFrameworkCore.PostgreSQL to a 3+ version I started running into this error.
Where and how do we check to make sure we're not concurrently accessing a connection? I know this is specific to my application, but I also have seen several other issues link to this one and no one seems to be detailing a method for implementing this work around and I'm honestly just completely perplexed.
roji commentedon Apr 20, 2020
@engineer-andrew I'm missing a lot of detail, but it sounds like you may be keeping a DbContext on a singleton service. DbContext instances, like connections, are not meant to be shared and can only be used once at a time. Assuming your service is a singleton (since multiple REST endpoints potentially access it at the same time), create a new DbContext each time you want to do a database operation (or more precisely, a unit of work). In general, don't store the instance in some member variable where others can use it - keep it in the stack for your own private us, and dispose it once you don't need anymore.
Hope that helps, if not you're going to have to provide a bit more context on what your application does.
engineer-andrew commentedon Apr 21, 2020
@roji Honestly, I posted my question mostly out of frustration with my problem and was not really expecting an answer. I definitely wasn't expecting an answer within 4 hours. And, of course, your answer sent me in the right direction. I'm using a Unit of Work pattern with a new DbContext created for each request (which is the unit of work). However, in one of my requests I was retrieving data from two repositories asynchronously. I somehow got so focused on the idea that it was the multiple requests coming into the API simultaneously that I was unable to see what was really causing the problem.
Thank you so much for getting back to me so quickly. I appreciate the help on this question and the overall work you're doing on this tool.
roji commentedon Apr 21, 2020
Glad I could help - FWIW this is a very common issue, and lots of people end up accidentally reusing the same DbContext concurrently.