Giter Site home page Giter Site logo

EntityWorkItemRepository.RunInTransaction leads to InvalidOperationException - the connection was not closed about webbackgrounder HOT 3 OPEN

TimLovellSmith avatar TimLovellSmith commented on August 24, 2024
EntityWorkItemRepository.RunInTransaction leads to InvalidOperationException - the connection was not closed

from webbackgrounder.

Comments (3)

aplcr avatar aplcr commented on August 24, 2024

Hi, I've been seeing this a lot too, and it seems to kill the job / stop it from recurring. Any thoughts?

from webbackgrounder.

TimLovellSmith avatar TimLovellSmith commented on August 24, 2024

So, read through EntityWorkItemRepository code a little.
EntityWorkItemRepository takes a factory thunk for creating contexts (IWorkItemsContext) which it

  1. steals the connection from
  2. runs a query
  3. disposes of the context and regenerates it IF no exception was thrown during the query

The problem scenario is likely that
a) first time we run a query we threw an exception
b) second time we run a query, the same context item gets reused, but since we already opened the connection for the previous query, boom.

from webbackgrounder.

TimLovellSmith avatar TimLovellSmith commented on August 24, 2024

Just found evidence to confirm the theory, so I'll work on the pull request.

Before the first InvalidOperationException in the logs we have a stack trace going through RunInTransaction.

System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Transaction (Process ID 495) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at StackExchange.Profiling.Data.ProfiledDbCommand.ExecuteNonQuery() in C:\Users\sam\Desktop\MiniProfiler\StackExchange.Profiling\Data\ProfiledDbCommand.cs:line 182 at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary2 identifierValues, List`1 generatedValues)
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
--- End of inner exception stack trace ---
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Entity.Internal.InternalContext.SaveChanges()
--- End of inner exception stack trace ---
at System.Data.Entity.Internal.InternalContext.SaveChanges()
at WebBackgrounder.EntityWorkItemRepository.SetWorkItemFailed(Int64 workItemId, Exception exception)
at WebBackgrounder.WebFarmJobCoordinator.<>c__DisplayClass7.b__6()
at WebBackgrounder.EntityWorkItemRepository.RunInTransaction(Action query)

from webbackgrounder.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.