villebro opened a new pull request, #43462: URL: https://github.com/apache/superset/pull/43462
### SUMMARY Addresses the P2 finding from the [#43407](https://github.com/apache/superset/pull/43407) review (targets `gaq-to-gtf`): the distributed lock's release is **ownership-less**. `AcquireDistributedLock` stored a constant value (`"1"` / `{"value": True}`) via `SET NX`, and `ReleaseDistributedLock` **unconditionally deleted** the key. So if holder A's TTL lapsed and holder B acquired the same key, A's `finally` release would **delete B's lock**. It predates this epic, but the epic makes this primitive central to task submit/cancel (`task_lock`), so it's worth closing. **Fix:** acquire now stores a **per-acquisition token** (`uuid4().hex`) as the lock's value; the `DistributedLock` context manager threads that token to release, which only deletes the key when the stored value still matches — **compare-and-delete**: - **Redis:** `get` → compare → `delete` (a get-then-delete; the residual non-atomic window is bounded by one round-trip and vastly smaller than an unconditional delete's exposure — a Lua CAS could close it fully; noted in a comment). - **KeyValue DB fallback:** ownership-checked read before delete. Release keeps a `token=None` mode meaning "delete unconditionally", which preserves the behavior of the one **cross-process** caller — the Excel export, where the API process acquires and the Celery task releases (they can't share an in-memory token). That path is unchanged. ### TESTING INSTRUCTIONS - `pytest tests/unit_tests/distributed_lock/` — two new regressions (Redis + KV) prove a superseded holder's release leaves the current holder's lock intact; existing happy-path / expiry / fallback tests updated for the token-shaped value (57 passing incl. export-excel which uses the unconditional path). - mypy / ruff / pre-commit clean. ### ADDITIONAL INFORMATION - [ ] Has associated issue - [ ] Required feature flags - [ ] Changes UI - [ ] Includes DB Migration - [ ] Introduces new feature or API - [ ] Removes existing feature or API -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
