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

fix segfaults on tests in debug builds for PyPy #744

Merged
merged 1 commit into from
Jul 6, 2023

Conversation

davidhewitt
Copy link
Contributor

Change Summary

This PR unifies the recursion guard limit between serialization and validation to 255 (thanks @adamreichold for the suggestion to move to a single limit).

I also add pytest.skip to a few tests which fail on PyPy with debug builds. This is because Rust debug builds don't optimize their stack space, so we hit trivial stack overflows.

Finally I add a test-debug job for PyPy 3.9 - can bump to PyPy 3.10 once the upstream PyO3 bug is fixed.

Related issue number

Ref #659
This should avoid crashes on debug builds with PyPy. (Doesn't close the full issue, which also exposes a bug in PyO3.)

Checklist

  • Unit tests for the changes exist
  • Documentation reflects the changes where applicable
  • Pydantic tests pass with this pydantic-core (except for expected changes)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

@codecov
Copy link

codecov bot commented Jul 5, 2023

Codecov Report

Merging #744 (7e8a88d) into main (d08d269) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #744   +/-   ##
=======================================
  Coverage   93.63%   93.63%           
=======================================
  Files          99       99           
  Lines       13895    13895           
  Branches       25       25           
=======================================
  Hits        13010    13010           
  Misses        879      879           
  Partials        6        6           
Impacted Files Coverage Δ
src/lib.rs 100.00% <100.00%> (ø)
src/recursion_guard.rs 95.65% <100.00%> (ø)
src/serializers/extra.rs 99.10% <100.00%> (-0.01%) ⬇️
src/validators/definitions.rs 88.49% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d08d269...7e8a88d. Read the comment docs.

@codspeed-hq
Copy link

codspeed-hq bot commented Jul 5, 2023

CodSpeed Performance Report

Merging #744 will improve performances by 12.51%

Comparing dh/pypy-segfaults (7e8a88d) with main (4527b80)

Summary

🔥 2 improvements
✅ 124 untouched benchmarks

Benchmarks breakdown

Benchmark main dh/pypy-segfaults Change
🔥 test_complete_core_json 2.8 ms 2.6 ms +10.13%
🔥 test_small_class_core_model 51.2 µs 45.5 µs +12.51%

@mgorny
Copy link
Contributor

mgorny commented Jul 5, 2023

Thank you! I can confirm that with this patch added, the tests no longer crash for me.

Copy link
Member

@adriangb adriangb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I noticed the other day is that this limit gets hit if you just nest a bunch of function validators, e.g.

schema = int_schema()
for _ in range(1000):
    schema = no_info_after_validator_function(lambda x: x, schema)

Not something we need to fix here, but just food for thought.

@davidhewitt
Copy link
Contributor Author

Yes, I think the best thing to consider would be that we make the recursion limit configurable. This is just a best-effort thing to protect users from segfaults on stack overflow, so if they think they have more stack space they could increase our limit safely.

Either we could make our limit configurable, or potentially we could use Py_EnterRecursiveCall to hang off Python's recursion limit. (I think that's 1000 by default, though will include Python calls. If we make our stack frames small enough that'll be fine.)

@davidhewitt davidhewitt merged commit ce68729 into main Jul 6, 2023
@davidhewitt davidhewitt deleted the dh/pypy-segfaults branch July 6, 2023 08:26
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.

3 participants