Skip to content

Commit

Permalink
Merge pull request #99 from eandersson/bug/97_v2
Browse files Browse the repository at this point in the history
Handle all channel opening within the lock
  • Loading branch information
eandersson committed May 25, 2021
2 parents 9cecbd3 + e858db2 commit e8f5c6f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions amqpstorm/connection.py
Expand Up @@ -183,16 +183,20 @@ def channel(self, rpc_timeout=60, lazy=False):
elif self.is_closed:
raise AMQPConnectionError('socket/connection closed')

with self.lock:
channel_id = None
self.lock.acquire()
try:
channel_id = self._get_next_available_channel_id()
channel = Channel(channel_id, self, rpc_timeout)
self._channels[channel_id] = channel
if not lazy:
channel.open()

channel.on_close_impl = self._cleanup_channel
LOGGER.debug('Channel #%d Opened', channel_id)
return self._channels[channel_id]
channel.on_close_impl = self._cleanup_channel
return self._channels[channel_id]
finally:
self.lock.release()
if channel_id is not None:
LOGGER.debug('Channel #%d Opened', channel_id)

def check_for_errors(self):
"""Check Connection for errors.
Expand Down

0 comments on commit e8f5c6f

Please sign in to comment.