Fix view retrying for PostgreSQL serialization errors (TransactionRollbackError) #222
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Websauna should automatically retry views if a retryable exception occurs. However, this is currently bugged: Websauna won't retry views where a
psycopg2.extensions.TransactionRollbackError
is thrown (ie. when a serialization error occurs in PostgreSQL)This can be tested manually by following instructions in this repo: https://github.com/koirikivi/websauna_retry_test
The first commit removes call to
request.tm.abort()
inwebsauna.system.core.views.internalservererror.internal_server_error
. This call should not be needed, aspyramid_tm
should handle the rollback in the case of an exception.The second commit amends
websauna.system.core.views.internalservererror.internal_server_error
to avoid spamminglogger.exception
when a view is retried. I'm less sure about the implementation here, though it seems to work empirically. Review kindly requested!Full story:
pyramid_retry
to handle view retryingpyramid_retry
needsrequest.exception
to retryrequest.invoke_exception_view
setsrequest.exception
but only ifit returns a view. If no exception view is configured,
request.exception
will beNone
.(websauna.system.core.views.internalservererror.internal_server_error),
However, this is disabled in development by default since debug toolbar is
enabled by default. In production settings, debug toolbar is disabled and
pyramid_retry
SHOULD work.request.tm.abort()
kills the current zope transaction,which causes a new transaction to be created when the retry process happens.
SessionDataManager
fromzope.sqlalchemy
attached, which means that it no longer knows how to retrycertain database exceptions, like those raised by psycopg2 when a
serialization error occurs.