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

bpo-29988: Only check evalbreaker after calls and on backwards egdes. #18334

Merged
merged 1 commit into from
Mar 24, 2021

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Feb 3, 2020

Makes sure that __exit__ or __aexit__ is called in (async) with statements, by not handling interrupts during set up of the with block.

We want to make sure that interrupts are always handled eventually, and ideally that they are handled promptly.
Checking eval_breaker on backward edges ensures that they are always handled eventually.
Checking after every explicit call ensures that they are handled promptly in most cases.

https://bugs.python.org/issue29988

@codecov
Copy link

codecov bot commented Feb 4, 2020

Codecov Report

Merging #18334 into master will increase coverage by 1.07%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           master   #18334       +/-   ##
===========================================
+ Coverage   82.11%   83.18%    +1.07%     
===========================================
  Files        1955     1570      -385     
  Lines      588629   414127   -174502     
  Branches    44407    44406        -1     
===========================================
- Hits       483351   344508   -138843     
+ Misses      95633    59978    -35655     
+ Partials     9645     9641        -4     
Impacted Files Coverage Δ
Lib/distutils/tests/test_bdist_rpm.py 30.00% <0.00%> (-65.00%) ⬇️
Lib/distutils/command/bdist_rpm.py 7.63% <0.00%> (-56.88%) ⬇️
Lib/test/test_urllib2net.py 76.92% <0.00%> (-13.85%) ⬇️
Lib/test/test_smtpnet.py 78.57% <0.00%> (-7.15%) ⬇️
Lib/ftplib.py 63.85% <0.00%> (-6.06%) ⬇️
Lib/test/test_ftplib.py 87.11% <0.00%> (-4.72%) ⬇️
Tools/scripts/db2pickle.py 17.82% <0.00%> (-3.97%) ⬇️
Tools/scripts/pickle2db.py 16.98% <0.00%> (-3.78%) ⬇️
Lib/test/test_socket.py 71.94% <0.00%> (-3.77%) ⬇️
Lib/test/test_asyncio/test_base_events.py 91.84% <0.00%> (-3.30%) ⬇️
... and 443 more

Continue to review full report at Codecov.

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

@serhiy-storchaka serhiy-storchaka self-requested a review March 14, 2020 13:49
@gpshead
Copy link
Member

gpshead commented Mar 15, 2020

Basically this moves the check for eval breaker to a select few points instead of being more frequent.

Any idea what negative consequences this could have?

Generally things like "what code pattern now prevents a ^C from raising a KeyboardInterrupt in a timely fashion" are how I anticipate this kind of change to manifest.

@gpshead gpshead requested review from ncoghlan and gpshead March 15, 2020 22:18
Copy link
Member

@gpshead gpshead left a comment

Choose a reason for hiding this comment

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

Overall I believe this is good, though I would like other reviewer eyeballs on it than just mine.

@csabella csabella requested review from ncoghlan and njsmith and removed request for njsmith and ncoghlan May 23, 2020 00:55
Copy link
Contributor

@ncoghlan ncoghlan left a comment

Choose a reason for hiding this comment

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

This needs test cases to make sure that it's actually solving the problem its aiming to solve.
The draft ones I wrote at the 2017 core dev sprints can be found at https://github.com/ncoghlan/cpython/pull/2/files (writing these test cases was the original reason we added per-opcode tracing support to the eval loop)

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@ncoghlan
Copy link
Contributor

Like @gpshead, this approach looks promising to me in principle - I like it a lot better than what I tried back in 2017. Removing the DISPATCH/FAST_DISPATCH distinction is also a nice bonus (effectively the opcodes that call the eval breaker are now the only ones not using fast dispatch).

So if we're super lucky, the test cases from my old branch will "just work" with this new code. And if they still don't pass, well, that's important to know as well :)

@markshannon
Copy link
Member Author

markshannon commented Jul 9, 2020

@ncoghlan
Adding tests only ensures that https://bugs.python.org/issue29988 doesn't manifest itself under some circumstances.
However, we know that this PR fixes the problem, because there can be no interrupt between the call to __enter__ and the exception handler being installed.
Having said that, a regression test is a good idea.
I've just had a look at your test. The one thing that I don't like is that it uses f_trace_opcodes, which exists purely to test for https://bugs.python.org/issue29988.
I'd like to remove f_trace_opcodes as its behaviour is undefined, because the sequence of bytecodes generated for any Python code is not defined.
Any ideas on how to test it without using f_trace_opcodes?

I've not tested your branch as https://github.com/ncoghlan/cpython/pull/2/files has some unrelated changes to ceval.c so won't rebase cleanly onto this branch.

XayOn added a commit to XayOn/pyrcrack that referenced this pull request Oct 8, 2020
With the new airmon-ng and airodump-ng APIs with async context managers,
proper properties for results and interfaces and callable objects, the
"simplified" interface that exposed the Pyrcrack class is no longer
needed.

Usage is more comprehensive now, and cleanup afterwards should work.
Altough examples seem to not wait for __aexit__ to cleanup (thus
airmon-ng's created interface would prevail) upon KeyboardInterrupt.

Might be caused by https://bugs.python.org/issue29988 wich relates to
bpo-29988 ( python/cpython#18334 )
@gpshead
Copy link
Member

gpshead commented Nov 21, 2020

@ncoghlan any thoughts on markshannon's question above?

@markshannon
Copy link
Member Author

@ncoghlan?

@ncoghlan
Copy link
Contributor

ncoghlan commented Jan 27, 2021

I added f_trace_opcodes specifically to enable the injection of exceptions after an arbitrary number of opcodes. The intended usage is the way I used it in the bpo-29988 test case: inject an exception after every bytecode offset and ensure they're all handled "as expected".

I didn't want to require a special build for the testing, nor rely on an undocumented feature, so we went ahead and published it, even though we didn't manage to fix the original bug report.

If we knew of another way to test this kind of thing, we wouldn't have needed to add f_trace_opcodes :)

… that __exit__ or __aexit__ is called in with statments in case of interrupt.
@markshannon markshannon force-pushed the fewer-checks-eval-breaker branch from 6afa580 to 9530e6d Compare March 24, 2021 17:22
@markshannon
Copy link
Member Author

I think this has sat around for long enough, time to merge.

@markshannon markshannon merged commit 4958f5d into python:master Mar 24, 2021
XayOn added a commit to XayOn/pyrcrack that referenced this pull request Apr 10, 2022
With the new airmon-ng and airodump-ng APIs with async context managers,
proper properties for results and interfaces and callable objects, the
"simplified" interface that exposed the Pyrcrack class is no longer
needed.

Usage is more comprehensive now, and cleanup afterwards should work.
Altough examples seem to not wait for __aexit__ to cleanup (thus
airmon-ng's created interface would prevail) upon KeyboardInterrupt.

Might be caused by https://bugs.python.org/issue29988 wich relates to
bpo-29988 ( python/cpython#18334 )
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.

5 participants