Fix check for server listen on auto-reload causing an SSL error in the server log because it was not connecting using SSL

This commit is contained in:
Kovid Goyal 2017-06-22 22:15:18 +05:30
parent c2d6ba54fa
commit 98b235e8e7
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
__license__ = 'GPL v3'
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
import os, sys, subprocess, signal, time, errno, socket
import os, sys, subprocess, signal, time, errno, socket, ssl
from threading import Thread, Lock
from Queue import Queue, Empty
@ -58,6 +58,7 @@ class WatcherBase(object):
def file_is_watched(self, fname):
return fname and fname.rpartition('.')[-1] in self.EXTENSIONS_TO_WATCH
if islinux:
import select
from calibre.utils.inotify import INotifyTreeWatcher
@ -249,6 +250,7 @@ class Worker(object):
opts = create_option_parser().parse_args(cmd)[0]
self.port = opts.port
self.uses_ssl = bool(opts.ssl_certfile and opts.ssl_keyfile)
self.connection_timeout = opts.timeout
self.retry_count = 0
t = Thread(name='PingThread', target=self.ping_thread)
@ -311,8 +313,14 @@ class Worker(object):
def wait_for_listen(self):
st = monotonic()
while monotonic() - st < 5:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(5)
try:
return socket.create_connection(('localhost', self.port), 5).close()
if self.uses_ssl:
s = ssl.wrap_socket(s)
s.connect(('localhost', self.port))
s.close()
return
except socket.error:
time.sleep(0.01)
self.log.error('Restarted server did not start listening on:', self.port)