classification
Title: test_socket crashes the whole test suite
Type: Stage: resolved
Components: Tests Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ddvento@ucar.edu, erob, martin.panter, neologix, pitrou, vstinner
Priority: normal Keywords: patch

Created on 2013-01-30 21:17 by ddvento@ucar.edu, last changed 2017-09-11 22:31 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
reset_sigalrm_handler.diff neologix, 2014-07-31 19:45 review
Pull Requests
URL Status Linked Edit
PR 3505 merged vstinner, 2017-09-11 22:03
Messages (13)
msg180993 - (view) Author: (ddvento@ucar.edu) Date: 2013-01-30 21:17
While running "make test" on my build of python 2.7.3 the suite aborts with

[..omiss..]
test_socket
make: *** [test] Alarm clock

Trying to run individually the offending test reveals a little more


$ ./python Lib/test/regrtest.py -v test_socket
== CPython 2.7.3 (default, Jan 29 2013, 11:23:48) [GCC 4.7.2]
==   Linux-2.6.32-220.13.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago little-endian
==   /glade/scratch/ddvento/build/Python-2.7.3-westmere/build/test_python_12171
Testing with flags: sys.flags(debug=0, py3k_warning=0, division_warning=0, division_new=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, tabcheck=0, verbose=0, unicode=0, bytes_warning=0, hash_randomization=0)
test_socket
TIPC module is not loaded, please 'sudo modprobe tipc'
testCrucialConstants (test.test_socket.GeneralModuleTests) ... ok
testDefaultTimeout (test.test_socket.GeneralModuleTests) ... ok
testGetServBy (test.test_socket.GeneralModuleTests) ... ok
testGetSockOpt (test.test_socket.GeneralModuleTests) ... ok
testGetaddrinfo (test.test_socket.GeneralModuleTests) ... ok
testHostnameRes (test.test_socket.GeneralModuleTests) ... ok
testIPv4_inet_aton_fourbytes (test.test_socket.GeneralModuleTests) ... ok
testIPv4toString (test.test_socket.GeneralModuleTests) ... ok
testIPv6toString (test.test_socket.GeneralModuleTests) ... ok
testInterpreterCrash (test.test_socket.GeneralModuleTests) ... ok
testListenBacklog0 (test.test_socket.GeneralModuleTests) ... ok
testNewAttributes (test.test_socket.GeneralModuleTests) ... ok
testNtoH (test.test_socket.GeneralModuleTests) ... ok
testNtoHErrors (test.test_socket.GeneralModuleTests) ... ok
testRefCountGetNameInfo (test.test_socket.GeneralModuleTests) ... ok
testSendAfterClose (test.test_socket.GeneralModuleTests) ... ok
testSendtoErrors (test.test_socket.GeneralModuleTests) ... ok
testSetSockOpt (test.test_socket.GeneralModuleTests) ... ok
testSockName (test.test_socket.GeneralModuleTests) ... ok
testSocketError (test.test_socket.GeneralModuleTests) ... ok
testStringToIPv4 (test.test_socket.GeneralModuleTests) ... ok
testStringToIPv6 (test.test_socket.GeneralModuleTests) ... ok
test_flowinfo (test.test_socket.GeneralModuleTests) ... ok
test_getsockaddrarg (test.test_socket.GeneralModuleTests) ... ok
test_sendall_interrupted (test.test_socket.GeneralModuleTests) ... FAIL
test_sendall_interrupted_with_timeout (test.test_socket.GeneralModuleTests) ... FAIL
test_sock_ioctl (test.test_socket.GeneralModuleTests) ... skipped 'Windows specific'
test_weakref (test.test_socket.GeneralModuleTests) ... ok
testDup (test.test_socket.BasicTCPTest) ... ok
testFromFd (test.test_socket.BasicTCPTest) ... ok
testOverFlowRecv (test.test_socket.BasicTCPTest) ... ok
testOverFlowRecvFrom (test.test_socket.BasicTCPTest) ... ok
testRecv (test.test_socket.BasicTCPTest) ... ok
testRecvFrom (test.test_socket.BasicTCPTest) ... ok
testSendAll (test.test_socket.BasicTCPTest) ... ok
testShutdown (test.test_socket.BasicTCPTest) ... ok
testClose (test.test_socket.TCPCloserTest) ... Alarm clock

$ echo $?
142

Of course my installation has an issue (which I'm trying to identify), but the test suite should not crash on a failure of individual test. I believe this is related to Issue1326841 in that the test author forgot to install the signal handler, or maybe was expecting the behavior Paul Rubin suggested in said bug.
msg181362 - (view) Author: (ddvento@ucar.edu) Date: 2013-02-04 18:19
So I rebuild python withou tipc (basically deleting it from configure, since it cannot be "cleanly" avoided, see Issue17092).

The 'sudo modprobe tipc' message of course disappears, but the uncaught alarm is still there, see below:

./python Lib/test/regrtest.py -v test_socket
== CPython 2.7.3 (default, Feb 2 2013, 11:27:13) [GCC 4.7.2]
==   Linux-2.6.32-220.13.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago little-endian
==   /glade/scratch/ddvento/build/Python-2.7.3-westmere-gdb-without-tipc/build/test_python_9390
Testing with flags: sys.flags(debug=0, py3k_warning=0, division_warning=0, division_new=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, tabcheck=0, verbose=0, unicode=0, bytes_warning=0, hash_randomization=0)
test_socket
testCrucialConstants (test.test_socket.GeneralModuleTests) ... ok
testDefaultTimeout (test.test_socket.GeneralModuleTests) ... ok
testGetServBy (test.test_socket.GeneralModuleTests) ... ok
testGetSockOpt (test.test_socket.GeneralModuleTests) ... ok
testGetaddrinfo (test.test_socket.GeneralModuleTests) ... ok
testHostnameRes (test.test_socket.GeneralModuleTests) ... ok
testIPv4_inet_aton_fourbytes (test.test_socket.GeneralModuleTests) ... ok
testIPv4toString (test.test_socket.GeneralModuleTests) ... ok
testIPv6toString (test.test_socket.GeneralModuleTests) ... ok
testInterpreterCrash (test.test_socket.GeneralModuleTests) ... ok
testListenBacklog0 (test.test_socket.GeneralModuleTests) ... ok
testNewAttributes (test.test_socket.GeneralModuleTests) ... ok
testNtoH (test.test_socket.GeneralModuleTests) ... ok
testNtoHErrors (test.test_socket.GeneralModuleTests) ... ok
testRefCountGetNameInfo (test.test_socket.GeneralModuleTests) ... ok
testSendAfterClose (test.test_socket.GeneralModuleTests) ... ok
testSendtoErrors (test.test_socket.GeneralModuleTests) ... ok
testSetSockOpt (test.test_socket.GeneralModuleTests) ... ok
testSockName (test.test_socket.GeneralModuleTests) ... ok
testSocketError (test.test_socket.GeneralModuleTests) ... ok
testStringToIPv4 (test.test_socket.GeneralModuleTests) ... ok
testStringToIPv6 (test.test_socket.GeneralModuleTests) ... ok
test_flowinfo (test.test_socket.GeneralModuleTests) ... ok
test_getsockaddrarg (test.test_socket.GeneralModuleTests) ... ok
test_sendall_interrupted (test.test_socket.GeneralModuleTests) ... FAIL
test_sendall_interrupted_with_timeout (test.test_socket.GeneralModuleTests) ... FAIL
test_sock_ioctl (test.test_socket.GeneralModuleTests) ... skipped 'Windows specific'
test_weakref (test.test_socket.GeneralModuleTests) ... ok
testDup (test.test_socket.BasicTCPTest) ... ok
testFromFd (test.test_socket.BasicTCPTest) ... ok
testOverFlowRecv (test.test_socket.BasicTCPTest) ... ok
testOverFlowRecvFrom (test.test_socket.BasicTCPTest) ... ok
testRecv (test.test_socket.BasicTCPTest) ... ok
testRecvFrom (test.test_socket.BasicTCPTest) ... ok
testSendAll (test.test_socket.BasicTCPTest) ... ok
testShutdown (test.test_socket.BasicTCPTest) ... ok
testClose (test.test_socket.TCPCloserTest) ... Alarm clock
msg181363 - (view) Author: (ddvento@ucar.edu) Date: 2013-02-04 18:25
Just to see this test running to completion, I applied the following (ugly) patch:

--- Lib/test/test_socket.py.orig    2012-04-09 17:07:32.000000000 -0600
+++ Lib/test/test_socket.py     2013-02-03 06:56:11.778118985 -0700
@@ -14,7 +14,7 @@
 import array
 import contextlib
 from weakref import proxy
-import signal
+#import signal
 import math
 
 def try_address(host, port=0, family=socket.AF_INET):
@@ -33,6 +33,12 @@
 MSG = b'Michael Gilfix was here\n'
 SUPPORTS_IPV6 = socket.has_ipv6 and try_address('::1', family=socket.AF_INET6)
 
+signal = "not a signal"
+
 try:
     import thread


With it, the test case completed as follows, which at least confirmed that the only broken part is sendall_interrupted. I'll live with it for now, but I'll be happy to work with the maintainer of these tests to understand what are they trying to accomplish, how to make them fail more gracefully (I tried installing a signal handler without success), and how to tell what to do to users of systems affected by the issue.


./python Lib/test/regrtest.py -v test_socket
== CPython 2.7.3 (default, Feb 2 2013, 11:27:13) [GCC 4.7.2]
==   Linux-2.6.32-220.13.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago little-endian
==   /glade/scratch/ddvento/build/Python-2.7.3-westmere-gdb-without-tipc/build/test_python_16005
Testing with flags: sys.flags(debug=0, py3k_warning=0, division_warning=0, division_new=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, tabcheck=0, verbose=0, unicode=0, bytes_warning=0, hash_randomization=0)
test_socket
testCrucialConstants (test.test_socket.GeneralModuleTests) ... ok
testDefaultTimeout (test.test_socket.GeneralModuleTests) ... ok
testGetServBy (test.test_socket.GeneralModuleTests) ... ok
testGetSockOpt (test.test_socket.GeneralModuleTests) ... ok
testGetaddrinfo (test.test_socket.GeneralModuleTests) ... ok
testHostnameRes (test.test_socket.GeneralModuleTests) ... ok
testIPv4_inet_aton_fourbytes (test.test_socket.GeneralModuleTests) ... ok
testIPv4toString (test.test_socket.GeneralModuleTests) ... ok
testIPv6toString (test.test_socket.GeneralModuleTests) ... ok
testInterpreterCrash (test.test_socket.GeneralModuleTests) ... ok
testListenBacklog0 (test.test_socket.GeneralModuleTests) ... ok
testNewAttributes (test.test_socket.GeneralModuleTests) ... ok
testNtoH (test.test_socket.GeneralModuleTests) ... ok
testNtoHErrors (test.test_socket.GeneralModuleTests) ... ok
testRefCountGetNameInfo (test.test_socket.GeneralModuleTests) ... ok
testSendAfterClose (test.test_socket.GeneralModuleTests) ... ok
testSendtoErrors (test.test_socket.GeneralModuleTests) ... ok
testSetSockOpt (test.test_socket.GeneralModuleTests) ... ok
testSockName (test.test_socket.GeneralModuleTests) ... ok
testSocketError (test.test_socket.GeneralModuleTests) ... ok
testStringToIPv4 (test.test_socket.GeneralModuleTests) ... ok
testStringToIPv6 (test.test_socket.GeneralModuleTests) ... ok
test_flowinfo (test.test_socket.GeneralModuleTests) ... ok
test_getsockaddrarg (test.test_socket.GeneralModuleTests) ... ok
test_sendall_interrupted (test.test_socket.GeneralModuleTests) ... skipped 'signal.alarm and socket.socketpair required for this test'
test_sendall_interrupted_with_timeout (test.test_socket.GeneralModuleTests) ... skipped 'signal.alarm and socket.socketpair required for this test'
test_sock_ioctl (test.test_socket.GeneralModuleTests) ... skipped 'Windows specific'
test_weakref (test.test_socket.GeneralModuleTests) ... ok
testDup (test.test_socket.BasicTCPTest) ... ok
testFromFd (test.test_socket.BasicTCPTest) ... ok
testOverFlowRecv (test.test_socket.BasicTCPTest) ... ok
testOverFlowRecvFrom (test.test_socket.BasicTCPTest) ... ok
testRecv (test.test_socket.BasicTCPTest) ... ok
testRecvFrom (test.test_socket.BasicTCPTest) ... ok
testSendAll (test.test_socket.BasicTCPTest) ... ok
testShutdown (test.test_socket.BasicTCPTest) ... ok
testClose (test.test_socket.TCPCloserTest) ... ok
testInterruptedTimeout (test.test_socket.TCPTimeoutTest) ... ok
testTCPTimeout (test.test_socket.TCPTimeoutTest) ... ok
testTimeoutZero (test.test_socket.TCPTimeoutTest) ... ok
testExceptionTree (test.test_socket.TestExceptions) ... ok
testRecvFromIntoArray (test.test_socket.BufferIOTest) ... ok
testRecvFromIntoBytearray (test.test_socket.BufferIOTest) ... ok
testRecvFromIntoMemoryview (test.test_socket.BufferIOTest) ... ok
testRecvIntoArray (test.test_socket.BufferIOTest) ... ok
testRecvIntoBytearray (test.test_socket.BufferIOTest) ... ok
testRecvIntoMemoryview (test.test_socket.BufferIOTest) ... ok
testDup (test.test_socket.BasicTCPTest2) ... ok
testFromFd (test.test_socket.BasicTCPTest2) ... ok
testOverFlowRecv (test.test_socket.BasicTCPTest2) ... ok
testOverFlowRecvFrom (test.test_socket.BasicTCPTest2) ... ok
testRecv (test.test_socket.BasicTCPTest2) ... ok
testRecvFrom (test.test_socket.BasicTCPTest2) ... ok
testSendAll (test.test_socket.BasicTCPTest2) ... ok
testShutdown (test.test_socket.BasicTCPTest2) ... ok
testRecvFrom (test.test_socket.BasicUDPTest) ... ok
testRecvFromNegative (test.test_socket.BasicUDPTest) ... ok
testSendtoAndRecv (test.test_socket.BasicUDPTest) ... ok
testTimeoutZero (test.test_socket.UDPTimeoutTest) ... ok
testUDPTimeout (test.test_socket.UDPTimeoutTest) ... ok
testAccept (test.test_socket.NonBlockingTCPTests) ... ok
testConnect (test.test_socket.NonBlockingTCPTests) ... ok
testRecv (test.test_socket.NonBlockingTCPTests) ... ok
testSetBlocking (test.test_socket.NonBlockingTCPTests) ... ok
testClosedAttr (test.test_socket.FileObjectClassTestCase) ... ok
testFullRead (test.test_socket.FileObjectClassTestCase) ... ok
testReadline (test.test_socket.FileObjectClassTestCase) ... ok
testReadlineAfterRead (test.test_socket.FileObjectClassTestCase) ... ok
testReadlineAfterReadNoNewline (test.test_socket.FileObjectClassTestCase) ... ok
testSmallRead (test.test_socket.FileObjectClassTestCase) ... ok
testUnbufferedRead (test.test_socket.FileObjectClassTestCase) ... ok
test_default (test.test_socket.FileObjectInterruptedTestCase) ... ok
test_no_buffer (test.test_socket.FileObjectInterruptedTestCase) ... ok
test_with_1k_buffer (test.test_socket.FileObjectInterruptedTestCase) ... ok
testClosedAttr (test.test_socket.UnbufferedFileObjectClassTestCase) ... ok
testFullRead (test.test_socket.UnbufferedFileObjectClassTestCase) ... ok
testReadline (test.test_socket.UnbufferedFileObjectClassTestCase) ... ok
testReadlineAfterRead (test.test_socket.UnbufferedFileObjectClassTestCase) ... ok
testReadlineAfterReadNoNewline (test.test_socket.UnbufferedFileObjectClassTestCase) ... ok
testSmallRead (test.test_socket.UnbufferedFileObjectClassTestCase) ... ok
testUnbufferedRead (test.test_socket.UnbufferedFileObjectClassTestCase) ... ok
testUnbufferedReadline (test.test_socket.UnbufferedFileObjectClassTestCase) ... ok
testClosedAttr (test.test_socket.LineBufferedFileObjectClassTestCase) ... ok
testFullRead (test.test_socket.LineBufferedFileObjectClassTestCase) ... ok
testReadline (test.test_socket.LineBufferedFileObjectClassTestCase) ... ok
testReadlineAfterRead (test.test_socket.LineBufferedFileObjectClassTestCase) ... ok
testReadlineAfterReadNoNewline (test.test_socket.LineBufferedFileObjectClassTestCase) ... ok
testSmallRead (test.test_socket.LineBufferedFileObjectClassTestCase) ... ok
testUnbufferedRead (test.test_socket.LineBufferedFileObjectClassTestCase) ... ok
testClosedAttr (test.test_socket.SmallBufferedFileObjectClassTestCase) ... ok
testFullRead (test.test_socket.SmallBufferedFileObjectClassTestCase) ... ok
testReadline (test.test_socket.SmallBufferedFileObjectClassTestCase) ... ok
testReadlineAfterRead (test.test_socket.SmallBufferedFileObjectClassTestCase) ... ok
testReadlineAfterReadNoNewline (test.test_socket.SmallBufferedFileObjectClassTestCase) ... ok
testSmallRead (test.test_socket.SmallBufferedFileObjectClassTestCase) ... ok
testUnbufferedRead (test.test_socket.SmallBufferedFileObjectClassTestCase) ... ok
testClose (test.test_socket.Urllib2FileobjectTest) ... ok
test_connect (test.test_socket.NetworkConnectionNoServer) ... ok
test_create_connection (test.test_socket.NetworkConnectionNoServer) ... ok
test_create_connection_timeout (test.test_socket.NetworkConnectionNoServer) ... ok
testFamily (test.test_socket.NetworkConnectionAttributesTest) ... ok
testSourceAddress (test.test_socket.NetworkConnectionAttributesTest) ... ok
testTimeoutDefault (test.test_socket.NetworkConnectionAttributesTest) ... ok
testTimeoutNone (test.test_socket.NetworkConnectionAttributesTest) ... ok
testTimeoutValueNamed (test.test_socket.NetworkConnectionAttributesTest) ... ok
testTimeoutValueNonamed (test.test_socket.NetworkConnectionAttributesTest) ... ok
testInsideTimeout (test.test_socket.NetworkConnectionBehaviourTest) ... ok
testOutsideTimeout (test.test_socket.NetworkConnectionBehaviourTest) ... ok
testRecv (test.test_socket.BasicSocketPairTest) ... ok
testSend (test.test_socket.BasicSocketPairTest) ... ok
testLinuxAbstractNamespace (test.test_socket.TestLinuxAbstractNamespace) ... ok
testMaxName (test.test_socket.TestLinuxAbstractNamespace) ... ok
testNameOverflow (test.test_socket.TestLinuxAbstractNamespace) ... ok

----------------------------------------------------------------------
Ran 113 tests in 9.957s

OK (skipped=3)
1 test OK.
msg189581 - (view) Author: Etienne Robillard (erob) Date: 2013-05-19 11:52
since TIPC is silently included in python 2.7.3 and recents kernel memory
leaks were found in the linux TIPC kernel code, could this result in info disclosure in python when compiled with TIPC ? does the kernel module needs to be loaded to exploit the memleaks from within python ? 

http://www.openwall.com/lists/oss-security/2013/04/14/3
msg189588 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-05-19 13:33
ddvento, I'm afraid you'll have to diagnose a bit more by tracing what happens during test_sendall_interrupted and test_sendall_interrupted_with_timeout. These test cases have a legitimate use for arming an alarm signal, but for some reason it seems the signal is triggered after those tests finish. Try printing exactly what happens at each step in those tests.

Etienne, I'm not sure what the issue specifically is. Is Linux TIPC has a memory leak issue, it isn't really Python's problem. If any case, it is a separate issue and therefore should be discussed on a separate bug entry.
msg190683 - (view) Author: (ddvento@ucar.edu) Date: 2013-06-05 17:35
The problem is that test_sendall_interrupted and 
test_sendall_interrupted_with_timeout make an assumption which is false 
on my hw, namely that it will take a long time for sendall() to 
complete. In fact, the following snippet:

from timeit import default_timer
import socket
c,s=socket.socketpair()
start = default_timer()
c.sendall("x" * (1024**2))
end= default_timer()
print end-start

probably fits some cache and runs in well less than 1ms (prints 
something between 0.000797 and 0.000876) on the server where this test 
is crashing (it takes forever on my laptop). Sending 1024**3 instead 
takes forever on the server too and makes the test pass. So the 
following patch is the least different for what you have now and it 
works on my server:

--- original/Python-2.7.5/Lib/test/test_socket.py    2013-05-11 
21:32:47.000000000 -0600
+++ Python-2.7.5/Lib/test/test_socket.py    2013-06-05 
11:20:59.390516537 -0600
@@ -685,11 +685,11 @@
                  c.settimeout(1.5)
              with self.assertRaises(ZeroDivisionError):
                  signal.alarm(1)
-                c.sendall(b"x" * (1024**2))
+                c.sendall(b"x" * (1024**3))
              if with_timeout:
                  signal.signal(signal.SIGALRM, ok_handler)
                  signal.alarm(1)
-                self.assertRaises(socket.timeout, c.sendall, b"x" * 
(1024**2))
+                self.assertRaises(socket.timeout, c.sendall, b"x" * 
(1024**3))
          finally:
              signal.signal(signal.SIGALRM, old_alarm)
              c.close()

However this is just waiting for a failure when a different hw will make 
the sendall faster again. I believe two more robust tests should be 
designed, without making assumptions about timing. Not sure it's 
possible, but it's certainly desirable.

Regards,
Davide Del Vento,
NCAR Computational & Information Services Laboratory
Consulting Services Software Engineer
http://www2.cisl.ucar.edu/uss/csg/
SEA Chair http://sea.ucar.edu/
office: Mesa Lab, Room 55G
office: (303) 497-1233
mobile: (303) 720-6338

On 05/19/2013 07:33 AM, Antoine Pitrou wrote:
> Antoine Pitrou added the comment:
>
> ddvento, I'm afraid you'll have to diagnose a bit more by tracing what happens during test_sendall_interrupted and test_sendall_interrupted_with_timeout. These test cases have a legitimate use for arming an alarm signal, but for some reason it seems the signal is triggered after those tests finish. Try printing exactly what happens at each step in those tests.
>
> Etienne, I'm not sure what the issue specifically is. Is Linux TIPC has a memory leak issue, it isn't really Python's problem. If any case, it is a separate issue and therefore should be discussed on a separate bug entry.
>
> ----------
> nosy: +pitrou
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue17085>
> _______________________________________
msg190684 - (view) Author: (ddvento@ucar.edu) Date: 2013-06-05 18:07
Note that the previous patch would still let the test suite crash if the 
sendall() takes a short enough time.

Having the test suite crash is so bad that I believe this should be the 
first issue to be fixed!

The following patch prevents the test suite from crashing (however, 
without the previous patch, it lets this particular test fail on my 
machine).

--- Python-2.7.5/Lib/test/test_socket.py    2013-05-11 
21:32:47.000000000 -0600
+++ Python-2.7.5-socket-fix/Lib/test/test_socket.py    2013-06-05 
12:05:41.038089911 -0600
@@ -691,6 +691,15 @@
                  signal.alarm(1)
                  self.assertRaises(socket.timeout, c.sendall, b"x" * 
(1024**2))
          finally:
+            # If c.sendall finishes before this process receives 
SIGALRM and
+            # the original signal handler is restored, the process will 
receive
+            # it and execute its default behavior of killing the
+            # interpreter. Make sure this doesn't happen by sleeping before
+            # restoring the original signal handler. Since only one alarm
+            # handler can be registered at once, we only need to sleep 
for 1
+            # second since both have been called with the same 1 second 
time
+            # argument.
+            time.sleep(1)
              signal.signal(signal.SIGALRM, old_alarm)
              c.close()
              s.close()

Regards,
Davide Del Vento,
NCAR Computational & Information Services Laboratory
Consulting Services Software Engineer
http://www2.cisl.ucar.edu/uss/csg/
SEA Chair http://sea.ucar.edu/
office: Mesa Lab, Room 55G
msg224438 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-31 18:35
Is this still an issue with Python 2.7.8? (I don't have 2.7 or linux to test on)
msg224443 - (view) Author: Charles-Fran├žois Natali (neologix) * (Python committer) Date: 2014-07-31 19:45
Thanks for the reminder Mark.
Yes, it is probably still an issue with the latest 2.7 release.

There were actually two issues:
- send send()/sendall() call didn't block because the test doesn't write enough data: we have since added a SOCK_MAX_SIZE constant to test_support just for that purpose, and the test has been updated, so it should now block (and succeed).
- the crash occurs because the test doesn't reset the alarm (with alarm(0)) upon exit, so if the alarm didn't go off during the test, it comes later when the original signal handler has been reset, and the default handler just exits.

To sum up, the first point is already fixed, and for the second point, here's a patch.

Note that 3.4 and default aren't affected, because the alarm is properly reset.
msg265525 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-05-14 12:33
The patch looks okay to me, to cancel the alarm before removing its signal handler.
msg301913 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-09-11 22:04
Charles-Fran├žois Natali:
> the crash occurs because the test doesn't reset the alarm (with alarm(0)) upon exit, so if the alarm didn't go off during the test, it comes later when the original signal handler has been reset, and the default handler just exits.
> (...)
> Note that 3.4 and default aren't affected, because the alarm is properly reset.

Right, I fixed this issue in the master branch: I proposed attached PR 3505 to backport the fix.
msg301919 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-09-11 22:31
New changeset 40996d3f6fbd1adcb2e69e426fa311aaf90762ff by Victor Stinner in branch '2.7':
bpo-17085: test_socket: cancel scheduled alarm on test failure (#3505)
https://github.com/python/cpython/commit/40996d3f6fbd1adcb2e69e426fa311aaf90762ff
msg301920 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-09-11 22:31
I believe that my commit 40996d3f6fbd1adcb2e69e426fa311aaf90762ff fixes the root issue in Python 2.7 and so I close the issue. Thanks for the bug report!
History
Date User Action Args
2017-09-11 22:31:50vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg301920

stage: patch review -> resolved
2017-09-11 22:31:19vstinnersetmessages: + msg301919
2017-09-11 22:04:38vstinnersetnosy: + vstinner
messages: + msg301913
2017-09-11 22:03:18vstinnersetpull_requests: + pull_request3498
2016-05-15 11:29:02BreamoreBoysetnosy: - BreamoreBoy
2016-05-14 12:33:44martin.pantersetnosy: + martin.panter

messages: + msg265525
stage: patch review
2014-07-31 19:45:10neologixsetfiles: + reset_sigalrm_handler.diff

nosy: + neologix
messages: + msg224443

keywords: + patch
2014-07-31 18:35:25BreamoreBoysetnosy: + BreamoreBoy
messages: + msg224438
2013-06-05 18:07:17ddvento@ucar.edusetmessages: + msg190684
2013-06-05 17:35:41ddvento@ucar.edusetmessages: + msg190683
2013-05-19 13:33:15pitrousetnosy: + pitrou
messages: + msg189588
2013-05-19 11:52:08erobsetnosy: + erob
messages: + msg189581
2013-02-04 18:25:54ddvento@ucar.edusetmessages: + msg181363
2013-02-04 18:19:56ddvento@ucar.edusetmessages: + msg181362
2013-01-30 21:17:08ddvento@ucar.educreate