Issue 10071: Should not release GIL while running RegEnumValue (original) (raw)

Created on 2010-10-12 11:43 by ocean-city, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (8)
msg118416 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2010-10-12 11:57
Currently, PC/winreg.c releases GIL while calling registry API, but I found this in Remarks section of RegEnumValue. http://msdn.microsoft.com/en-us/library/ms724865%28VS.85%29.aspx > While using RegEnumValue, an application should not call any registry > functions that might change the key being queried. Maybe we shouldn't release GIL in PC/winreg.c? Thank you.
msg118493 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-10-13 00:35
Some of your submission appears to have gotten lost (I saw it via email). Below is the patch you proposed. I haven't experienced this crash on my machines, but the solution seems fine to me. # I sometimes experienced crash of test_changing_value(test_winreg) # on release27-maint. It happens when 2 threads calls PyEnumValue and # PySetValue simultaneously. And I could stop it by following patch. # I'll attach the stack trace of crash. Index: PC/_winreg.c =================================================================== --- PC/_winreg.c (revision 85344) +++ PC/_winreg.c (working copy) @@ -1219,7 +1219,6 @@ } while (1) { - Py_BEGIN_ALLOW_THREADS rc = RegEnumValue(hKey, index, retValueBuf, @@ -1228,7 +1227,6 @@ &typ, (BYTE *)retDataBuf, &retDataSize); - Py_END_ALLOW_THREADS if (rc != ERROR_MORE_DATA) break; @@ -1577,9 +1575,7 @@ if (subKey == NULL) return NULL; } - Py_BEGIN_ALLOW_THREADS rc = RegSetValue(hKey, subKey, REG_SZ, str, len+1); - Py_END_ALLOW_THREADS if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValue"); Py_INCREF(Py_None);
msg118499 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-10-13 02:43
Hirokazu, could you run Python in a debugger and figure out exactly which line crashes and what the error is? I'm curious. If we make this change, the same change should be applied to RegEnumKey, etc., since the RegEnumKey docs contain similar language.
msg118508 - (view) Author: Hirokazu Yamamoto (ocean-city) * (Python committer) Date: 2010-10-13 09:55
One thread is exactly on RegEnumValue or RegQueryValue, and another thread is a bit after RegSetValue (the place varies case by case). Type is SEGV.
msg192649 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-07-08 13:11
LGTM I suggest that you add a comment with a link to this issue. People may wonder why some places don't release the GIL.
msg224597 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-08-03 00:06
Apart from the request for a comment made in it looks as if this can be commited.
msg224732 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2014-08-04 15:21
I don't think this is an appropriate fix, since in most cases there is no need to prevent other Python threads running while inside RegSetValue. There are also other ways that a context switch may occur during the enumeration which will put the program in exactly the same state. (It isn't clear from the patch, but the two sections of changed code are from completely different functions.) The correct fix should be at the user's application level, or in a higher-level module than _winreg is supposed to be.
msg404253 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2021-10-19 00:11
With Steve's opposition and the fact that we've gotten along for 11 years since this issue was opened without it (and also without further reports of issues), I'm going to go ahead and close the issue.
History
Date User Action Args
2022-04-11 14:57:07 admin set github: 54280
2021-10-19 00:11:04 zach.ware set status: open -> closedresolution: rejectedmessages: + stage: patch review -> resolved
2019-04-26 20:24:22 BreamoreBoy set nosy: - BreamoreBoy
2014-08-04 15:21:07 steve.dower set messages: +
2014-08-03 00:06:28 BreamoreBoy set nosy: + BreamoreBoy, tim.golden, zach.ware, steve.dower, - brian.curtinmessages: + versions: + Python 3.5, - Python 3.3
2013-07-08 13:11:59 christian.heimes set nosy: + christian.heimesmessages: + versions: + Python 3.3, Python 3.4, - Python 3.1, Python 3.2
2010-10-13 09:55:40 ocean-city set messages: +
2010-10-13 09:47:06 ocean-city set messages: -
2010-10-13 09:36:52 ocean-city set messages: +
2010-10-13 02:43:15 stutzbach set messages: +
2010-10-13 00:35:05 brian.curtin set nosy: + stutzbach, brian.curtinmessages: + components: + Windowstype: crashstage: patch review
2010-10-12 11:57:30 ocean-city set status: closed -> openmessages: +
2010-10-12 11:56:58 ocean-city set status: open -> closed
2010-10-12 11:56:28 ocean-city set -> (no value)messages: -
2010-10-12 11:56:16 ocean-city set files: - py27_test_winreg_crash_stack_trace.txt
2010-10-12 11:48:19 ocean-city set messages: +
2010-10-12 11:46:17 ocean-city set -> (no value)messages: -
2010-10-12 11:43:22 ocean-city create