Commit fbd5797e authored by Jeremy Hylton's avatar Jeremy Hylton

Fix for SF bug 453099 -- select not defensive

And SF patch 473223 -- infinite getattr loop

Wrap select() and poll() calls with try/except for EINTR.  If EINTR is
raised, treat as a response where no fd is ready.

In dispatcher constructor, make sure self.socket is always
initialized.
parent 2836907b
...@@ -53,7 +53,7 @@ import sys ...@@ -53,7 +53,7 @@ import sys
import os import os
from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, \ from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, \
ENOTCONN, ESHUTDOWN ENOTCONN, ESHUTDOWN, EINTR
try: try:
socket_map socket_map
...@@ -66,7 +66,6 @@ class ExitNow (exceptions.Exception): ...@@ -66,7 +66,6 @@ class ExitNow (exceptions.Exception):
DEBUG = 0 DEBUG = 0
def poll (timeout=0.0, map=None): def poll (timeout=0.0, map=None):
global DEBUG
if map is None: if map is None:
map = socket_map map = socket_map
if map: if map:
...@@ -76,7 +75,11 @@ def poll (timeout=0.0, map=None): ...@@ -76,7 +75,11 @@ def poll (timeout=0.0, map=None):
r.append (fd) r.append (fd)
if obj.writable(): if obj.writable():
w.append (fd) w.append (fd)
r,w,e = select.select (r,w,e, timeout) try:
r,w,e = select.select (r,w,e, timeout)
except select.error, err:
if err[0] != EINTR:
raise
if DEBUG: if DEBUG:
print r,w,e print r,w,e
...@@ -158,7 +161,12 @@ def poll3 (timeout=0.0, map=None): ...@@ -158,7 +161,12 @@ def poll3 (timeout=0.0, map=None):
flags = flags | select.POLLOUT flags = flags | select.POLLOUT
if flags: if flags:
pollster.register(fd, flags) pollster.register(fd, flags)
r = pollster.poll (timeout) try:
r = pollster.poll (timeout)
except select.error, err:
if err[0] != EINTR:
raise
r = []
for fd, flags in r: for fd, flags in r:
try: try:
obj = map[fd] obj = map[fd]
...@@ -205,6 +213,8 @@ class dispatcher: ...@@ -205,6 +213,8 @@ class dispatcher:
self.socket.setblocking (0) self.socket.setblocking (0)
self.connected = 1 self.connected = 1
self.addr = sock.getpeername() self.addr = sock.getpeername()
else:
self.socket = None
def __repr__ (self): def __repr__ (self):
status = [self.__class__.__module__+"."+self.__class__.__name__] status = [self.__class__.__module__+"."+self.__class__.__name__]
...@@ -241,7 +251,8 @@ class dispatcher: ...@@ -241,7 +251,8 @@ class dispatcher:
self.add_channel() self.add_channel()
def set_socket (self, sock, map=None): def set_socket (self, sock, map=None):
self.__dict__['socket'] = sock self.socket = sock
## self.__dict__['socket'] = sock
self._fileno = sock.fileno() self._fileno = sock.fileno()
self.add_channel (map) self.add_channel (map)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment