Commit daca97cb authored by Jim Fulton's avatar Jim Fulton

Awful hack to run the server multi-threaded

Because running it single-threaded was unstable, at least in the tests.

See http://bugs.python.org/issue27392
parent da2e2281
...@@ -50,7 +50,7 @@ from ZODB.POSException import TransactionError, ReadOnlyError, ConflictError ...@@ -50,7 +50,7 @@ from ZODB.POSException import TransactionError, ReadOnlyError, ConflictError
from ZODB.serialize import referencesf from ZODB.serialize import referencesf
from ZODB.utils import oid_repr, p64, u64, z64 from ZODB.utils import oid_repr, p64, u64, z64
from .asyncio.server import Acceptor from .asyncio.mtacceptor import Acceptor
logger = logging.getLogger('ZEO.StorageServer') logger = logging.getLogger('ZEO.StorageServer')
......
...@@ -81,13 +81,8 @@ class Acceptor(asyncore.dispatcher): ...@@ -81,13 +81,8 @@ class Acceptor(asyncore.dispatcher):
asyncore.dispatcher.__init__(self, map=self.__socket_map) asyncore.dispatcher.__init__(self, map=self.__socket_map)
self.ssl_context = ssl self.ssl_context = ssl
if ssl is not None:
self.ssl_wrap_socket = ssl.wrap_socket
self._open_socket() self._open_socket()
def ssl_wrap_socket(self, sock, server_side):
return sock
def _open_socket(self): def _open_socket(self):
addr = self.addr addr = self.addr
...@@ -165,17 +160,32 @@ class Acceptor(asyncore.dispatcher): ...@@ -165,17 +160,32 @@ class Acceptor(asyncore.dispatcher):
try: try:
logger.debug("new connection %s" % (addr,)) logger.debug("new connection %s" % (addr,))
sock = self.ssl_wrap_socket(sock, server_side=True)
def run(): def run():
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop) asyncio.set_event_loop(loop)
zs = self.storage_server.create_client_handler() zs = self.storage_server.create_client_handler()
protocol = ServerProtocol(loop, self.addr, zs) protocol = ServerProtocol(loop, self.addr, zs)
protocol.stop = loop.stop protocol.stop = loop.stop
asyncio.async(loop.create_connection((lambda : protocol),
sock=sock), if self.ssl_context is None:
loop=loop) cr = loop.create_connection((lambda : protocol), sock=sock)
else:
#######################################################
# XXX See http://bugs.python.org/issue27392 :(
_make_ssl_transport = loop._make_ssl_transport
def make_ssl_transport(*a, **kw):
kw['server_side'] = True
return _make_ssl_transport(*a, **kw)
loop._make_ssl_transport = make_ssl_transport
#
#######################################################
cr = loop.create_connection(
(lambda : protocol), sock=sock,
ssl=self.ssl_context,
server_hostname='fu' # http://bugs.python.org/issue27391
)
asyncio.async(cr, loop=loop)
loop.run_forever() loop.run_forever()
loop.close() loop.close()
......
...@@ -1089,7 +1089,7 @@ def runzeo_without_configfile(): ...@@ -1089,7 +1089,7 @@ def runzeo_without_configfile():
------ ------
--T INFO ZEO.StorageServer StorageServer created RW with storages 1RWt --T INFO ZEO.StorageServer StorageServer created RW with storages 1RWt
------ ------
--T INFO ZEO.asyncio.server listening on ... --T INFO ZEO.asyncio... listening on ...
------ ------
--T INFO ZEO.StorageServer closing storage '1' --T INFO ZEO.StorageServer closing storage '1'
testing exit immediately testing exit immediately
......
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