[issue39776] PyContextVar_Get(): crash due to race condition in updating tstate->id

2020-03-04 Thread Yury Selivanov


Yury Selivanov  added the comment:

Thank you so much, Stefan, for looking into this. Really appreciate the help.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39776] PyContextVar_Get(): crash due to race condition in updating tstate->id

2020-03-04 Thread Evgeny Boytsov


Evgeny Boytsov  added the comment:

I checked both my test example and real production code with your patch. I'm 
unable to reproduce the bug, so I think it is fixed now. Thank you!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39776] PyContextVar_Get(): crash due to race condition in updating tstate->id

2020-03-03 Thread Stefan Krah


Stefan Krah  added the comment:

Thanks Ned, closing then.


Evgeny, please reopen if you see it again (I ran the tests for about
20 min, way above the usual reproduction time of 1 min).

Thanks for the very instructive test case!

--
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39776] PyContextVar_Get(): crash due to race condition in updating tstate->id

2020-03-03 Thread Ned Deily


Ned Deily  added the comment:

Thanks for the heads-up and the fix, Stefan. The fix for 3.7.x was merged 
before the 3.7.7rc1 cutoff (by a few hours!) and the next 3.8.x release cutoff 
is planned for April and 3.9.0a5 is later in March, so, if you are not planning 
to merge any other changes for this issue, we can set the issue status to 
"closed" now.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39776] PyContextVar_Get(): crash due to race condition in updating tstate->id

2020-03-03 Thread Stefan Krah


Change by Stefan Krah :


--
resolution:  -> fixed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39776] PyContextVar_Get(): crash due to race condition in updating tstate->id

2020-03-03 Thread Stefan Krah


Change by Stefan Krah :


--
stage: patch review -> resolved

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39776] PyContextVar_Get(): crash due to race condition in updating tstate->id

2020-03-03 Thread Stefan Krah


Stefan Krah  added the comment:

Setting to release blocker, but please move to deferred again
if a release is almost finished.

--
nosy: +lukasz.langa, ned.deily
priority: deferred blocker -> release blocker

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39776] PyContextVar_Get(): crash due to race condition in updating tstate->id

2020-03-03 Thread Stefan Krah


Stefan Krah  added the comment:

Also _pydecimal was affected. This is a modified version of Evgeny's
test case:

from _pydecimal import *
from time import sleep
from random import randint
import sys


sys.setswitchinterval(0.001)


def usleep(x):
sleep(x/100.0)

class Test:

def __init__(self, threadno):
self.threadno = threadno

def GetCallback(self):
usleep(randint(0, 9));
setcontext(Context(Emax=self.threadno))
usleep(randint(0, 9))
c = getcontext()
try:
if c.Emax != self.threadno:
raise RuntimeError("GetCallback: another thread changed this 
thread's context")
except AttributeError:
raise RuntimeError("GetCallback: type(c)==%s and c.Emax 
disappeared" % type(c))
usleep(randint(0, 9))
return self.Callback

def Callback(self):
c = getcontext()
try:
c.Emax = self.threadno
except AttributeError:
raise RuntimeError("Callback: type(c)==%s and c.Emax disappeared" % 
type(c))

def DoTest(threadno):
return Test(threadno).GetCallback()



It produces one of the exceptions or a segfault. You may have
to build in release mode to get the race.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39776] PyContextVar_Get(): crash due to race condition in updating tstate->id

2020-03-03 Thread Stefan Krah


Change by Stefan Krah :


Added file: https://bugs.python.org/file48945/pydecimal_cases.zip

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39776] PyContextVar_Get(): crash due to race condition in updating tstate->id

2020-03-03 Thread Stefan Krah


Stefan Krah  added the comment:

Since many duplicate tstate ids are generated in the test case
before the crash happens, I guess a set of tstates with the same
id silently uses the cached context of the "winner" tstate.

This can lead to incorrect results without noticing.

--
priority: critical -> deferred blocker

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39776] PyContextVar_Get(): crash due to race condition in updating tstate->id

2020-03-03 Thread Stefan Krah


Change by Stefan Krah :


--
assignee:  -> skrah

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39776] PyContextVar_Get(): crash due to race condition in updating tstate->id

2020-03-03 Thread Stefan Krah


Change by Stefan Krah :


--
title: Crash in decimal module in heavy-multithreaded scenario -> 
PyContextVar_Get(): crash due to race condition in updating tstate->id

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com