Skip to content

Commit 9569dda

Browse files
Handle "OSError: [Errno 9] Bad file descriptor" crash on OS X.
1 parent 67b23c7 commit 9569dda

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

pymux/server.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,16 @@ def _recv(self):
4646
(Parse it.)
4747
"""
4848
# Read next chunk.
49-
data = self.connection.recv(1024)
49+
try:
50+
data = self.connection.recv(1024)
51+
except OSError as e:
52+
# On OSX, when we try to create a new window by typing "pymux
53+
# new-window" in a centain pane, very often we get the following
54+
# error: "OSError: [Errno 9] Bad file descriptor."
55+
# This doesn't seem very harmful, and we can just try again.
56+
logger.warning('Got OSError while reading data from client: %s. '
57+
'Trying again.', e)
58+
return
5059

5160
if data == b'':
5261
# End of file. Close connection.
@@ -65,7 +74,13 @@ def _process(self, data):
6574
"""
6675
Process packet received from client.
6776
"""
68-
packet = json.loads(data.decode('utf-8'))
77+
try:
78+
packet = json.loads(data.decode('utf-8'))
79+
except ValueError:
80+
# So far, this never happened. But it would be good to have some
81+
# protection.
82+
logger.warning('Received invalid JSON from client. Ignoring.')
83+
return
6984

7085
# Handle commands.
7186
if packet['cmd'] == 'run-command':

0 commit comments

Comments
 (0)