Skip to content

Commit

Permalink
Prevent TLS from closing randomly (#49)
Browse files Browse the repository at this point in the history
Keep references to bare transport objects to prevent GC from deleting them prematurely, as deletion of transport objects closes underlying sockets. Such behaviour breaks write operations and totally ruins loop which listens for incoming read events from socket (see also #43)
  • Loading branch information
Alexander Oblovatniy authored and Waldemar Quevedo committed Dec 6, 2017
1 parent a0929cd commit 5a5e3f6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions nats/aio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from nats.aio.utils import new_inbox
from nats.protocol.parser import *

__version__ = '0.6.2'
__version__ = '0.6.3'
__lang__ = 'python3'
PROTOCOL = 1

Expand Down Expand Up @@ -104,7 +104,9 @@ def __init__(self):
self._pings_outstanding = 0
self._pongs_received = 0
self._pongs = []
self._bare_io_reader = None
self._io_reader = None
self._bare_io_writer = None
self._io_writer = None
self._err = None
self._error_cb = None
Expand Down Expand Up @@ -582,8 +584,8 @@ def _select_next_server(self):
loop=self._loop,
limit=DEFAULT_BUFFER_SIZE)
srv = s
self._io_reader = r
self._io_writer = w
self._bare_io_reader = self._io_reader = r
self._bare_io_writer = self._io_writer = w
break
except Exception as e:
self._err = e
Expand Down Expand Up @@ -866,6 +868,7 @@ def _process_connect_init(self):
if not sock:
# This shouldn't happen
raise NatsError('nats: unable to get socket')

yield from self._io_writer.drain() # just in case something is left

self._io_reader, self._io_writer = \
Expand Down

0 comments on commit 5a5e3f6

Please sign in to comment.