-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
bpo-31061: fix crash in asyncio speedup module #2966
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
Changes from 3 commits
336a6ce
4fd34a6
97ccf31
a67847e
e126945
de3ee01
6a02050
503806f
f900058
483586b
b4589ce
fa2b42b
3ca521d
b0fb8e7
f32e949
7bc0c2a
55a2eb5
3033b15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -962,14 +962,18 @@ FutureObj_dealloc(PyObject *self) | |
{ | ||
FutureObj *fut = (FutureObj *)self; | ||
|
||
PyObject_GC_UnTrack(self); | ||
|
||
if (Future_CheckExact(fut)) { | ||
/* When fut is subclass of Future, finalizer is called from | ||
* subtype_dealloc. | ||
*/ | ||
PyObject_GC_Track(self); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, you're right. it's needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm just following what was done in https://bugs.python.org/issue26617. I think it's worth someone grepping through the whole codebase, I saw several other places that maybe needed this. It seems like every dealloc should have a PyObject_GC_UnTrack at the top? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, noddy4 example should do it at first :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw how do we get this into 3.6.3 as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the type has There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I filed an issue for that. http://bugs.python.org/issue31095 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. k, should I remove the LRU change I added here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, please. asyncio speedup module is introduced from Python 3.6. |
||
if (PyObject_CallFinalizerFromDealloc(self) < 0) { | ||
// resurrected. | ||
return; | ||
} | ||
PyObject_GC_UnTrack(self); | ||
} | ||
|
||
if (fut->fut_weakreflist != NULL) { | ||
|
@@ -1836,14 +1840,18 @@ TaskObj_dealloc(PyObject *self) | |
{ | ||
TaskObj *task = (TaskObj *)self; | ||
|
||
PyObject_GC_UnTrack(self); | ||
|
||
if (Task_CheckExact(self)) { | ||
/* When fut is subclass of Task, finalizer is called from | ||
* subtype_dealloc. | ||
*/ | ||
PyObject_GC_Track(self); | ||
if (PyObject_CallFinalizerFromDealloc(self) < 0) { | ||
// resurrected. | ||
return; | ||
} | ||
PyObject_GC_UnTrack(self); | ||
} | ||
|
||
if (task->task_weakreflist != NULL) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move PyObject_GC_UnTrack after this if block, and remove Track and Untrack in the block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but that would mean this (34fae03) is wrong too then no?
because it first does an UnTrack: 34fae03#diff-c3cf251f16d5a03a9e7d4639f2d6f998L1113
With the same Track/Untrack pattern here:
34fae03#diff-c3cf251f16d5a03a9e7d4639f2d6f998R1129
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current code:
I proposed:
34fae03 does other things between UnTrack() and Track()
But this code does only
Future_CheckExact()
and it is safe.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k, I'm claiming ignorance since I don't know what these macros achieve :) I'd personally feel safer if we had a test case, do you know how to create a testcase to cause this to crash? Mine takes a day to reproduce in a production environment :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CPython's circular reference GC uses doubly linked list to track object which can be member of circular reference.
PyObject_GC_UnTrack()
removes object from the list, andPyObject_GC_Track()
insert the object to the list.Despite very undetarministic multithreading, I can cause SEGV quickly with this code:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! I'll add testcases and add your suggestions, thanks so much for all the help!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k, added FutureObj testcase, have a good test case for the TaskObj? Not quite sure how to trigger it.