Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5adff3f

Browse files
gh-80931: Skip some socket tests while hunting for refleaks on macOS (#114057)
Some socket tests related to sending file descriptors cause a file descriptor leak on macOS, all of them tests that send one or more descriptors than cannot be received on the read end. This appears to be a platform bug. This PR skips those tests when doing a refleak test run to avoid hiding other problems.
1 parent 47133d8 commit 5adff3f

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

Lib/test/libregrtest/refleak.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from test import support
77
from test.support import os_helper
8+
from test.support import refleak_helper
89

910
from .runtests import HuntRefleak
1011
from .utils import clear_caches
@@ -96,7 +97,12 @@ def get_pooled_int(value):
9697
support.gc_collect()
9798

9899
for i in rep_range:
99-
results = test_func()
100+
current = refleak_helper._hunting_for_refleaks
101+
refleak_helper._hunting_for_refleaks = True
102+
try:
103+
results = test_func()
104+
finally:
105+
refleak_helper._hunting_for_refleaks = current
100106

101107
dash_R_cleanup(fs, ps, pic, zdc, abcs)
102108
support.gc_collect()

Lib/test/support/refleak_helper.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""
2+
Utilities for changing test behaviour while hunting
3+
for refleaks
4+
"""
5+
6+
_hunting_for_refleaks = False
7+
def hunting_for_refleaks():
8+
return _hunting_for_refleaks

Lib/test/test_socket.py

+49
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from test.support import os_helper
44
from test.support import socket_helper
55
from test.support import threading_helper
6+
from test.support import refleak_helper
67

78
import _thread as thread
89
import array
@@ -52,6 +53,35 @@
5253
except ImportError:
5354
_socket = None
5455

56+
def skipForRefleakHuntinIf(condition, issueref):
57+
if not condition:
58+
def decorator(f):
59+
f.client_skip = lambda f: f
60+
return f
61+
62+
else:
63+
def decorator(f):
64+
@contextlib.wraps(f)
65+
def wrapper(*args, **kwds):
66+
if refleak_helper.hunting_for_refleaks():
67+
raise unittest.SkipTest(f"ignore while hunting for refleaks, see {issueref}")
68+
69+
return f(*args, **kwds)
70+
71+
def client_skip(f):
72+
@contextlib.wraps(f)
73+
def wrapper(*args, **kwds):
74+
if refleak_helper.hunting_for_refleaks():
75+
return
76+
77+
return f(*args, **kwds)
78+
79+
return wrapper
80+
wrapper.client_skip = client_skip
81+
return wrapper
82+
83+
return decorator
84+
5585
def get_cid():
5686
if fcntl is None:
5787
return None
@@ -3814,6 +3844,7 @@ def checkTruncatedHeader(self, result, ignoreflags=0):
38143844
self.checkFlags(flags, eor=True, checkset=socket.MSG_CTRUNC,
38153845
ignore=ignoreflags)
38163846

3847+
@skipForRefleakHuntinIf(sys.platform == "darwin", "#80931")
38173848
def testCmsgTruncNoBufSize(self):
38183849
# Check that no ancillary data is received when no buffer size
38193850
# is specified.
@@ -3823,40 +3854,49 @@ def testCmsgTruncNoBufSize(self):
38233854
# received.
38243855
ignoreflags=socket.MSG_CTRUNC)
38253856

3857+
@testCmsgTruncNoBufSize.client_skip
38263858
def _testCmsgTruncNoBufSize(self):
38273859
self.createAndSendFDs(1)
38283860

3861+
@skipForRefleakHuntinIf(sys.platform == "darwin", "#80931")
38293862
def testCmsgTrunc0(self):
38303863
# Check that no ancillary data is received when buffer size is 0.
38313864
self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG), 0),
38323865
ignoreflags=socket.MSG_CTRUNC)
38333866

3867+
@testCmsgTrunc0.client_skip
38343868
def _testCmsgTrunc0(self):
38353869
self.createAndSendFDs(1)
38363870

38373871
# Check that no ancillary data is returned for various non-zero
38383872
# (but still too small) buffer sizes.
38393873

3874+
@skipForRefleakHuntinIf(sys.platform == "darwin", "#80931")
38403875
def testCmsgTrunc1(self):
38413876
self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG), 1))
38423877

3878+
@testCmsgTrunc1.client_skip
38433879
def _testCmsgTrunc1(self):
38443880
self.createAndSendFDs(1)
38453881

3882+
@skipForRefleakHuntinIf(sys.platform == "darwin", "#80931")
38463883
def testCmsgTrunc2Int(self):
38473884
# The cmsghdr structure has at least three members, two of
38483885
# which are ints, so we still shouldn't see any ancillary
38493886
# data.
38503887
self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG),
38513888
SIZEOF_INT * 2))
38523889

3890+
@testCmsgTrunc2Int.client_skip
38533891
def _testCmsgTrunc2Int(self):
38543892
self.createAndSendFDs(1)
38553893

3894+
@skipForRefleakHuntinIf(sys.platform == "darwin", "#80931")
38563895
def testCmsgTruncLen0Minus1(self):
38573896
self.checkTruncatedHeader(self.doRecvmsg(self.serv_sock, len(MSG),
38583897
socket.CMSG_LEN(0) - 1))
38593898

3899+
@testCmsgTruncLen0Minus1.client_skip
38603900
def _testCmsgTruncLen0Minus1(self):
38613901
self.createAndSendFDs(1)
38623902

@@ -3887,29 +3927,38 @@ def checkTruncatedArray(self, ancbuf, maxdata, mindata=0):
38873927
len(cmsg_data) - (len(cmsg_data) % fds.itemsize)])
38883928
self.checkFDs(fds)
38893929

3930+
@skipForRefleakHuntinIf(sys.platform == "darwin", "#80931")
38903931
def testCmsgTruncLen0(self):
38913932
self.checkTruncatedArray(ancbuf=socket.CMSG_LEN(0), maxdata=0)
38923933

3934+
@testCmsgTruncLen0.client_skip
38933935
def _testCmsgTruncLen0(self):
38943936
self.createAndSendFDs(1)
38953937

3938+
@skipForRefleakHuntinIf(sys.platform == "darwin", "#80931")
38963939
def testCmsgTruncLen0Plus1(self):
38973940
self.checkTruncatedArray(ancbuf=socket.CMSG_LEN(0) + 1, maxdata=1)
38983941

3942+
@testCmsgTruncLen0Plus1.client_skip
38993943
def _testCmsgTruncLen0Plus1(self):
39003944
self.createAndSendFDs(2)
39013945

3946+
@skipForRefleakHuntinIf(sys.platform == "darwin", "#80931")
39023947
def testCmsgTruncLen1(self):
39033948
self.checkTruncatedArray(ancbuf=socket.CMSG_LEN(SIZEOF_INT),
39043949
maxdata=SIZEOF_INT)
39053950

3951+
@testCmsgTruncLen1.client_skip
39063952
def _testCmsgTruncLen1(self):
39073953
self.createAndSendFDs(2)
39083954

3955+
3956+
@skipForRefleakHuntinIf(sys.platform == "darwin", "#80931")
39093957
def testCmsgTruncLen2Minus1(self):
39103958
self.checkTruncatedArray(ancbuf=socket.CMSG_LEN(2 * SIZEOF_INT) - 1,
39113959
maxdata=(2 * SIZEOF_INT) - 1)
39123960

3961+
@testCmsgTruncLen2Minus1.client_skip
39133962
def _testCmsgTruncLen2Minus1(self):
39143963
self.createAndSendFDs(2)
39153964

0 commit comments

Comments
 (0)