Skip to content

Fix DynamoDB backend: tolerate ResourceInUseException when pool processes race to create the result table - #11106

Merged
auvipy merged 3 commits into
celery:mainfrom
tony1233200:fix/11087-dynamodb-create-table-race
Nov 24, 2026
Merged

auvipy merged 3 commits into
celery:mainfrom
tony1233200:fix/11087-dynamodb-create-table-race

Conversation

@tony1233200

Copy link
Copy Markdown
Contributor

Problem

Fixes #11087.

When the DynamoDB result table does not exist yet, every pool process of a worker tries to create it on its first result write. The processes that lose the race get ResourceInUseException from create_table, and DynamoDBBackend._get_or_create_table() lets it propagate — so the result write fails and a task that ran fine is stored as FAILURE. This is a regression from #7734, which dropped the ResourceInUseException tolerance the backend had up to 5.2.x.

Fix

In _get_or_create_table(), wrap the create_table call: on ResourceInUseException, treat it as "another process is creating the table" — wait for the table to become ACTIVE via the existing _wait_for_table_status() and return a fresh describe_table. Any other ClientError from create_table still propagates unchanged.

Tests

New unit tests in t/unit/backends/test_dynamodb.py:

  • test_get_or_create_table_create_race — describe → ResourceNotFoundException, create → ResourceInUseException, then describe returns the ACTIVE table. Fails without the fix (the ClientError propagates), passes with it.
  • test_get_or_create_table_create_other_error — a different create error (ValidationException) still propagates and no wait happens.

Full file: t/unit/backends/test_dynamodb.py — 40 passed with the fix; the new race test fails on unpatched main. flake8 clean.

Disclosure: this change was prepared with the assistance of an AI coding tool; the diagnosis, reproduction and test results above were verified locally by running the test suite.

…sses race to create the result table

When the result table does not exist yet, every pool process tries to
create it on its first write. The losers' create_table raises
ResourceInUseException, which _get_or_create_table let through, so the
result write failed and the task was stored as FAILURE although it ran.
Treat the error as 'another process is creating it': wait for the table
to become ACTIVE and describe it, as the backend did before celery#7734.
@tony1233200

This comment was marked as abuse.

@auvipy

auvipy commented Nov 22, 2026

Copy link
Copy Markdown
Member

there is no need for rush. the review Q is pretty long

@auvipy auvipy reopened this Nov 22, 2026
@auvipy auvipy added this to the 5.7.x milestone Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.35%. Comparing base (0b6df69) to head (46cb8d9).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11106   +/-   ##
=======================================
  Coverage   91.35%   91.35%           
=======================================
  Files         153      153           
  Lines       21889    21896    +7     
  Branches     2721     2722    +1     
=======================================
+ Hits        19997    20004    +7     
  Misses       1590     1590           
  Partials      302      302           
Flag Coverage Δ
unittests 91.34% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@auvipy
auvipy merged commit 98ddb11 into celery:main Nov 24, 2026
531 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DynamoDB backend: pool processes race to create a missing table, and tasks that ran are stored as FAILURE

2 participants