Skip to content

Commit

Permalink
Workaround for wrong errno on socket bind permission errors on Cygwin.
Browse files Browse the repository at this point in the history
  • Loading branch information
embray authored and Steven Silvester committed Jun 7, 2020
1 parent b5b44eb commit 7aa6891
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions notebook/notebookapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1725,14 +1725,21 @@ def _bind_http_server_tcp(self):
try:
self.http_server.listen(port, self.ip)
except socket.error as e:
eacces = (errno.EACCES, getattr(errno, 'WSAEACCES', errno.EACCES))
if sys.platform == 'cygwin':
# Cygwin has a bug that causes EPERM to be returned in this
# case instead of EACCES:
# https://cygwin.com/ml/cygwin/2019-04/msg00160.html
eacces += (errno.EPERM,)

if e.errno == errno.EADDRINUSE:
if self.port_retries:
self.log.info(_('The port %i is already in use, trying another port.') % port)
else:
self.log.info(_('The port %i is already in use.') % port)
continue
elif e.errno in (errno.EACCES, getattr(errno, 'WSAEACCES', errno.EACCES)):
self.log.warning(_("Permission to listen on port %i denied.") % port)
elif e.errno in eacces:
self.log.warning(_("Permission to listen on port %i denied") % port)
continue
else:
raise
Expand Down

0 comments on commit 7aa6891

Please sign in to comment.