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

Use the Python frame safely in _pythonCallstack #88993

Closed
wants to merge 1 commit into from

Conversation

charlie-wt
Copy link
Contributor

@charlie-wt charlie-wt commented Nov 14, 2022

Currently, the result of PyEval_GetFrame() is piped straight to Py_INCREF. However, PyEval_GetFrame may return null, which seems to be the case sometimes, when calling _pythonCallstack from another thread. This is handled in the subsequent while (nullptr != frame) block, but Py_INCREF, called before it, doesn't handle this case, so the program segfaults. The safe form of Py_INCREF is Py_XINCREF, so use that instead (docs).

@pytorch-bot pytorch-bot bot added the release notes: jit release notes category label Nov 14, 2022
@pytorch-bot
Copy link

pytorch-bot bot commented Nov 14, 2022

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/88993

Note: Links to docs will display an error until the docs builds have been completed.

⏳ No Failures, 1 Pending

As of commit 1434444:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 14, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

@charlie-wt charlie-wt closed this Nov 14, 2022
@charlie-wt charlie-wt reopened this Nov 16, 2022
@davidberard98 davidberard98 added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 16, 2022
@facebook-github-bot
Copy link
Contributor

@davidberard98 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Collaborator

@albanD albanD left a comment

Choose a reason for hiding this comment

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

SGTM

@albanD
Copy link
Collaborator

albanD commented Nov 16, 2022

@pytorchbot merge -g

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks on your PR pass since you used the green (-g) flag (ETA: 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@malfet malfet added this to the 1.13.1 milestone Nov 17, 2022
@malfet
Copy link
Contributor

malfet commented Nov 17, 2022

May be worth considering for 1.13.1, though it would be good to have some sort of regression test for it

@charlie-wt
Copy link
Contributor Author

May be worth considering for 1.13.1, though it would be good to have some sort of regression test for it

Yes, I'd like it if this made it in for 1.13.1 since it was causing crashes with the IPU backend without a manual workaround.

weiwangmeta pushed a commit to weiwangmeta/pytorch that referenced this pull request Nov 30, 2022
Currently, the result of `PyEval_GetFrame()` is piped straight to `Py_INCREF`. However, `PyEval_GetFrame` [may return null](https://docs.python.org/3/c-api/reflection.html#c.PyEval_GetFrame), which seems to be the case sometimes, when calling `_pythonCallstack` from another thread. This is handled in the subsequent `while (nullptr != frame)` block, but `Py_INCREF`, called before it, [doesn't handle this case](https://docs.python.org/3/c-api/refcounting.html#c.Py_INCREF), so the program segfaults. The safe form of `Py_INCREF` is `Py_XINCREF`, so use that instead ([docs](https://docs.python.org/3/c-api/refcounting.html#c.Py_XINCREF)).
Pull Request resolved: pytorch#88993
Approved by: https://github.com/albanD
weiwangmeta pushed a commit to weiwangmeta/pytorch that referenced this pull request Dec 6, 2022
Currently, the result of `PyEval_GetFrame()` is piped straight to `Py_INCREF`. However, `PyEval_GetFrame` [may return null](https://docs.python.org/3/c-api/reflection.html#c.PyEval_GetFrame), which seems to be the case sometimes, when calling `_pythonCallstack` from another thread. This is handled in the subsequent `while (nullptr != frame)` block, but `Py_INCREF`, called before it, [doesn't handle this case](https://docs.python.org/3/c-api/refcounting.html#c.Py_INCREF), so the program segfaults. The safe form of `Py_INCREF` is `Py_XINCREF`, so use that instead ([docs](https://docs.python.org/3/c-api/refcounting.html#c.Py_XINCREF)).
Pull Request resolved: pytorch#88993
Approved by: https://github.com/albanD
kulinseth pushed a commit to kulinseth/pytorch that referenced this pull request Dec 10, 2022
Currently, the result of `PyEval_GetFrame()` is piped straight to `Py_INCREF`. However, `PyEval_GetFrame` [may return null](https://docs.python.org/3/c-api/reflection.html#c.PyEval_GetFrame), which seems to be the case sometimes, when calling `_pythonCallstack` from another thread. This is handled in the subsequent `while (nullptr != frame)` block, but `Py_INCREF`, called before it, [doesn't handle this case](https://docs.python.org/3/c-api/refcounting.html#c.Py_INCREF), so the program segfaults. The safe form of `Py_INCREF` is `Py_XINCREF`, so use that instead ([docs](https://docs.python.org/3/c-api/refcounting.html#c.Py_XINCREF)).
Pull Request resolved: pytorch#88993
Approved by: https://github.com/albanD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request Merged open source release notes: jit release notes category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants