Skip to content

Serialize overlapping once calls across threads - #406

Merged
dgilland merged 2 commits into
dgilland:developfrom
jwalith4418-Mj:fix/once-concurrent-calls
Nov 1, 2026
Merged

dgilland merged 2 commits into
dgilland:developfrom
jwalith4418-Mj:fix/once-concurrent-calls

Conversation

@jwalith4418-Mj

Copy link
Copy Markdown
Contributor

Fixes #402.

Two overlapping calls can both enter a once() callback before either sets called, producing different results and repeating side effects. Serialize callback execution and cache access with a reentrant lock. Exceptions still allow a later retry, and same-thread recursion retains its existing behavior. Exclude the process-local lock from pickle state and recreate it when restoring the wrapper.

The regression holds the first callback open while a second thread calls the wrapper. It fails against develop (6d33598) and passes with the fix. Additional controls cover exception retries, a cached None, recursive calls, and pickling before and after the first call.

Validation on Windows / Python 3.12:

  • Standard project test selection: pytest src/pydash tests --ignore=tests/pytest_mypy_testing --cov=pydash -q: 3,084 passed, 100% coverage.
  • Full Ruff check and formatting check; mypy src/pydash tests tasks.py --no-error-summary: passed.
  • Strict Sphinx HTML build and sdist/wheel build: passed.
  • Ubuntu / Python 3.10: all 117 function tests passed.

An additional run including the optional pytest_mypy_testing directory produced 335 reveal-type expectation failures with the installed mypy. An isolated, unchanged worktree at 6d33598 produces the identical 335 failing node IDs. The normal tasks.py test command excludes that optional directory; no test expectations were changed to mask these failures.

AI assistance: this patch, tests and description were prepared and validated with OpenAI Codex. No human-review attestation is implied.

Guard callback execution and cached state with a reentrant lock. Preserve exception retries, recursive calls, and pickling.

AI-assisted: prepared and validated with OpenAI Codex.
@coveralls

coveralls commented Nov 1, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same — jwalith4418-Mj:fix/once-concurrent-calls into dgilland:develop

@dgilland
dgilland merged commit f0a616b into dgilland:develop Nov 1, 2026
5 checks passed
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.

once can execute its callback twice when calls overlap across threads

3 participants