Skip to content

Commit 7b2b437

Browse files
committed
downgrade rather than ignore malformed socket warning
1 parent a13e948 commit 7b2b437

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

Lib/test/test_socket.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from test import support
33
from test.support import (
44
is_apple, os_helper, refleak_helper, socket_helper, threading_helper,
5-
warnings_helper,
65
)
76
import _thread as thread
87
import array
@@ -200,12 +199,20 @@ def socket_setdefaulttimeout(timeout):
200199

201200

202201
@contextlib.contextmanager
203-
def catch_malformed_data_warning(quiet=True):
202+
def downgrade_malformed_data_warning():
204203
# This warning happens on macos and win, but does not always happen on linux.
205-
with warnings_helper.check_warnings(
206-
("received malformed or improperly-truncated ancillary data", RuntimeWarning),
207-
quiet=quiet,
208-
):
204+
if sys.platform not in {"win32", "darwin"}:
205+
yield
206+
return
207+
208+
with warnings.catch_warnings():
209+
# TODO: gh-110012, we should investigate why this warning is happening
210+
# and fix it properly.
211+
warnings.simplefilter(
212+
"always:"
213+
r"received malformed or improperly-truncated ancillary data"
214+
":RuntimeWarning"
215+
)
209216
yield
210217

211218

@@ -3957,7 +3964,7 @@ def checkTruncatedArray(self, ancbuf, maxdata, mindata=0):
39573964
# mindata and maxdata bytes when received with buffer size
39583965
# ancbuf, and that any complete file descriptor numbers are
39593966
# valid.
3960-
with catch_malformed_data_warning():
3967+
with downgrade_malformed_data_warning(): # TODO: gh-110012
39613968
msg, ancdata, flags, addr = self.doRecvmsg(self.serv_sock,
39623969
len(MSG), ancbuf)
39633970
self.assertEqual(msg, MSG)
@@ -4310,7 +4317,7 @@ def testSingleCmsgTruncInData(self):
43104317
self.serv_sock.setsockopt(socket.IPPROTO_IPV6,
43114318
socket.IPV6_RECVHOPLIMIT, 1)
43124319
self.misc_event.set()
4313-
with catch_malformed_data_warning():
4320+
with downgrade_malformed_data_warning(): # TODO: gh-110012
43144321
msg, ancdata, flags, addr = self.doRecvmsg(
43154322
self.serv_sock, len(MSG), socket.CMSG_LEN(SIZEOF_INT) - 1)
43164323

@@ -4415,7 +4422,7 @@ def testSecondCmsgTruncInData(self):
44154422
self.serv_sock.setsockopt(socket.IPPROTO_IPV6,
44164423
socket.IPV6_RECVTCLASS, 1)
44174424
self.misc_event.set()
4418-
with catch_malformed_data_warning():
4425+
with downgrade_malformed_data_warning(): # TODO: gh-110012
44194426
msg, ancdata, flags, addr = self.doRecvmsg(
44204427
self.serv_sock, len(MSG),
44214428
socket.CMSG_SPACE(SIZEOF_INT) + socket.CMSG_LEN(SIZEOF_INT) - 1)

0 commit comments

Comments
 (0)