[pypy-commit] pypy default: Issue #3049

arigo pypy.commits at gmail.com
Thu Aug 8 03:37:26 EDT 2019


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r97097:8819acbf633a
Date: 2019-08-08 09:27 +0200
http://bitbucket.org/pypy/pypy/changeset/8819acbf633a/

Log:	Issue #3049

	There were a missing "except SocketError" converting interp-level
	exceptions to app-level ones---or, as it turns out, eating them
	completely in a couple of cases.

diff --git a/pypy/module/_socket/interp_socket.py b/pypy/module/_socket/interp_socket.py
--- a/pypy/module/_socket/interp_socket.py
+++ b/pypy/module/_socket/interp_socket.py
@@ -312,7 +312,10 @@
                 raise converted_error(space, e)
         if buflen < 0 or buflen > 1024:
             raise explicit_socket_error(space, "getsockopt buflen out of range")
-        return space.newbytes(self.sock.getsockopt(level, optname, buflen))
+        try:
+            return space.newbytes(self.sock.getsockopt(level, optname, buflen))
+        except SocketError as e:
+            raise converted_error(space, e)
 
     def gettimeout_w(self, space):
         """gettimeout() -> timeout
@@ -438,7 +441,10 @@
         setblocking(True) is equivalent to settimeout(None);
         setblocking(False) is equivalent to settimeout(0.0).
         """
-        self.sock.setblocking(flag)
+        try:
+            self.sock.setblocking(flag)
+        except SocketError as e:
+            pass    # CPython 2 only: never raise anything here
 
     @unwrap_spec(level=int, optname=int)
     def setsockopt_w(self, space, level, optname, w_optval):
@@ -477,7 +483,10 @@
             timeout = space.float_w(w_timeout)
             if timeout < 0.0:
                 raise oefmt(space.w_ValueError, "Timeout value out of range")
-        self.sock.settimeout(timeout)
+        try:
+            self.sock.settimeout(timeout)
+        except SocketError as e:
+            pass    # CPython 2 only: never raise anything here
 
     @unwrap_spec(nbytes=int, flags=int)
     def recv_into_w(self, space, w_buffer, nbytes=0, flags=0):
diff --git a/pypy/module/_socket/test/test_sock_app.py b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -872,6 +872,14 @@
         cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         assert cli.family == socket.AF_INET
 
+    def test_missing_error_catching(self):
+        from _socket import socket, error
+        s = socket()
+        s.close()
+        s.settimeout(1)          # EBADF, but ignored on Python 2
+        s.setblocking(True)      # EBADF, but ignored on Python 2
+        raises(error, s.getsockopt, 42, 84, 8)    # EBADF
+
 
 class AppTestErrno:
     spaceconfig = {'usemodules': ['_socket']}


More information about the pypy-commit mailing list