Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction error #2594

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Transaction error #2594

wants to merge 2 commits into from

Conversation

ttichy
Copy link

@ttichy ttichy commented May 16, 2023

@oskardudycz we discussed this a long time ago on gitter and you asked me to make a PR with a failing test. So about 8 months later, here it is :)

I am having issues with npgsql elevating transactions to prepared and then failing with
55000: prepared transactions are disabled

I modified enlist_in_transaction_scope_by_transaction test, so it skips the bulk insertion inside fixtureSetup.
Notice that without the bulk insertion, the seemingly textbook case of enrolling in a transaction fails with the error message above.

@ttichy
Copy link
Author

ttichy commented May 16, 2023

The difference between the working and non-working case (as far as I can tell) is that in the non-working case there is one extra call to ConnectionFactory.Create().
This extra connection comes from Database.EnsureStorageExists() call inside DocumentSessionBase. I am guessing that this connection is not disposed of, Npgsql sees two connections and elevates the transaction to distributed/prepared

@oskardudycz oskardudycz force-pushed the master branch 6 times, most recently from 6f60ad6 to 0a7a351 Compare July 22, 2023 13:01
@mysticmind
Copy link
Member

@ttichy The changes what you have done is failing due to expected and actual values being different and not due to the error 55000: prepared transactions are disabled which you have outlined in the issue:

CoreTests.ability_to_use_an_existing_connection_and_transaction.pass_in_current_connection_and_transaction_with_externally_controlled_tx_boundaries_async [FAIL]
  [xUnit.net 00:00:28.22]     CoreTests.ability_to_use_an_existing_connection_and_transaction.pass_in_current_connection_and_transaction [FAIL]
    Failed CoreTests.ability_to_use_an_existing_connection_and_transaction.pass_in_current_connection_and_transaction_async [8 ms]
    Error Message:
     Shouldly.ShouldAssertException : await query.Query<Target>().CountAsync()
      should be
  100
      but was
  0
    Stack Trace:
       at CoreTests.ability_to_use_an_existing_connection_and_transaction.pass_in_current_connection_and_transaction_async() in /home/runner/work/marten/marten/src/CoreTests/ability_to_use_an_existing_connection_and_transaction.cs:line 205
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at CoreTests.ability_to_use_an_existing_connection_and_transaction.pass_in_current_connection_and_transaction_async() in /home/runner/work/marten/marten/src/CoreTests/ability_to_use_an_existing_connection_and_transaction.cs:line 206
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at CoreTests.ability_to_use_an_existing_connection_and_transaction.pass_in_current_connection_and_transaction_async() in /home/runner/work/marten/marten/src/CoreTests/ability_to_use_an_existing_connection_and_transaction.cs:line 213
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  --- End of stack trace from previous location ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    Failed CoreTests.ability_to_use_an_existing_connection_and_transaction.can_query_async_with_session_enlisted_in_transaction_scope [13 ms]
    Error Message:
     System.InvalidOperationException : Sequence contains no elements
    Stack Trace:
       at Marten.Linq.QueryHandlers.OneResultHandler`1.HandleAsync(DbDataReader reader, IMartenSession session, CancellationToken token) in /home/runner/work/marten/marten/src/Marten/Linq/QueryHandlers/OneResultHandler.cs:line 87
     at Marten.Linq.MartenLinqQueryProvider.ExecuteHandlerAsync[T](IQueryHandler`1 handler, CancellationToken token)
     at Marten.Linq.MartenLinqQueryProvider.ExecuteHandlerAsync[T](IQueryHandler`1 handler, CancellationToken token) in /home/runner/work/marten/marten/src/Marten/Linq/MartenLinqQueryProvider.cs:line 141
     at JasperFx.Core.Exceptions.ExceptionTransformExtensions.TransformAndThrow(IEnumerable`1 transforms, Exception ex)
     at JasperFx.Core.Exceptions.ExceptionTransforms.TransformAndThrow(Exception ex)
     at Marten.Exceptions.MartenExceptionTransformer.WrapAndThrow(Exception exception) in /home/runner/work/marten/marten/src/Marten/Exceptions/MartenExceptionTransformer.cs:line 51
     at Marten.Linq.MartenLinqQueryProvider.ExecuteHandlerAsync[T](IQueryHandler`1 handler, CancellationToken token) in /home/runner/work/marten/marten/src/Marten/Linq/MartenLinqQueryProvider.cs:line 145
     at Marten.Linq.MartenLinqQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken token, ResultOperatorBase op)
     at JasperFx.Core.Exceptions.ExceptionTransformExtensions.TransformAndThrow(IEnumerable`1 transforms, Exception ex)
     at JasperFx.Core.Exceptions.ExceptionTransforms.TransformAndThrow(Exception ex)
     at Marten.Exceptions.MartenExceptionTransformer.WrapAndThrow(Exception exception) in /home/runner/work/marten/marten/src/Marten/Exceptions/MartenExceptionTransformer.cs:line 51
     at Marten.Linq.MartenLinqQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken token, ResultOperatorBase op) in /home/runner/work/marten/marten/src/Marten/Linq/MartenLinqQueryProvider.cs:line 104
     at CoreTests.ability_to_use_an_existing_connection_and_transaction.can_query_async_with_session_enlisted_in_transaction_scope() in /home/runner/work/marten/marten/src/CoreTests/ability_to_use_an_existing_connection_and_transaction.cs:line 87
     at CoreTests.ability_to_use_an_existing_connection_and_transaction.can_query_async_with_session_enlisted_in_transaction_scope() in /home/runner/work/marten/marten/src/CoreTests/ability_to_use_an_existing_connection_and_transaction.cs:line 93
  --- End of stack trace from previous location ---
    Failed CoreTests.ability_to_use_an_existing_connection_and_transaction.pass_in_current_connection_and_transaction_with_externally_controlled_tx_boundaries_async [16 ms]
    Error Message:

Could you please recheck using the latest Marten version and get back to us?

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