classification
Title: test_descr: test_vicious_descriptor_nonsense() fails randomly
Type: Stage: resolved
Components: Tests, Windows Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: pablogsal, paul.moore, serhiy.storchaka, steve.dower, tim.golden, zach.ware
Priority: normal Keywords: patch

Created on 2019-02-25 21:15 by pablogsal, last changed 2019-02-26 10:55 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 12044 merged serhiy.storchaka, 2019-02-26 05:38
Messages (7)
msg336554 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-02-25 21:15
https://buildbot.python.org/all/#/builders/32/builds/2198

======================================================================
ERROR: test_vicious_descriptor_nonsense (test.test_descr.ClassPropertiesAndMethods)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\buildarea\3.x.bolen-windows8\build\lib\test\test_descr.py", line 4341, in test_vicious_descriptor_nonsense
    self.assertEqual(c.attr, 1)
  File "D:\buildarea\3.x.bolen-windows8\build\lib\test\test_descr.py", line 4328, in __eq__
    del C.attr
AttributeError: attr
----------------------------------------------------------------------
Ran 140 tests in 7.836s
msg336557 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-02-25 21:20
I can reproduce this locally. How has this not being spotted by the CI:

❯ ./python.exe -m test test_descr
Run tests sequentially
0:00:00 load avg: 3.82 [1/1] test_descr
test test_descr failed -- Traceback (most recent call last):
  File "/Users/pgalindo3/github/cpython/Lib/test/test_descr.py", line 4341, in test_vicious_descriptor_nonsense
    self.assertEqual(c.attr, 1)
  File "/Users/pgalindo3/github/cpython/Lib/test/test_descr.py", line 4328, in __eq__
    del C.attr
AttributeError: attr

test_descr failed

== Tests result: FAILURE ==

1 test failed:
    test_descr

Total duration: 2 sec 437 ms
Tests result: FAILURE
msg336560 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-02-25 21:37
It seems that this is a race condition created as a consequence of:

https://github.com/python/cpython/pull/11112/files
msg336609 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-02-26 05:50
Although 12044 fixes the problem, something a bit more fundamental may have changed. I have spent time investigating why this is happening and the problem is that in the line:


self.assertEqual(c.attr, 1)

Evil.__eq__ is invoked twice where before it was only invoked once. This does not happen all the time, and it seems to only happen under some combination of hashes in the class dictionary, being the extra __eq__ invocation a check for equality when looking up attr in the c object. When the test succeeds, the extra check is not done (and therefore the attribute is not deleted). I think this happens because some identity is used to check when doing the lookup (comparing the pointers) but I would like to understand exactly how the hash is influencing the different code paths to be sure that nothing important has changed recently.
msg336612 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-02-26 06:00
Ok, actually this turns to be much easier: Sometimes __eq__ was also called twice but now as we use PyDict_GetItemWithError instead of PyDict_GetItem, if the extra __eq__ happens as a consequence of a dict lookup the error is ignored so that was the reason the test was not failing before.
msg336613 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-02-26 06:03
New changeset ff3d39faa8aa28308cc5eae6843eaac514da8fd8 by Pablo Galindo (Serhiy Storchaka) in branch 'master':
bpo-36109: Fix random test_descr failure. (GH-12044)
https://github.com/python/cpython/commit/ff3d39faa8aa28308cc5eae6843eaac514da8fd8
msg336614 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-02-26 06:05
A lot of buildbots were failing for this test so a lot of them will become green after ff3d39faa8aa28308cc5eae6843eaac514da8fd8.
History
Date User Action Args
2019-02-26 10:55:55vstinnersettitle: test_descr fails on AMD64 Windows8 3.x buildbots -> test_descr: test_vicious_descriptor_nonsense() fails randomly
2019-02-26 06:05:27pablogsalsetmessages: + msg336614
2019-02-26 06:03:51pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-02-26 06:03:23pablogsalsetmessages: + msg336613
2019-02-26 06:00:08pablogsalsetmessages: + msg336612
2019-02-26 05:50:16pablogsalsetmessages: + msg336609
2019-02-26 05:50:04pablogsalsetmessages: - msg336608
2019-02-26 05:49:46pablogsalsetmessages: + msg336608
2019-02-26 05:38:59serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request12070
2019-02-25 21:37:27pablogsalsetnosy: + serhiy.storchaka
messages: + msg336560
2019-02-25 21:20:10pablogsalsetmessages: + msg336557
2019-02-25 21:15:44pablogsalcreate