Commit 0e64224d authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Set response state before sending to avoid race

parent 5d499c8d
Loading
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -189,11 +189,13 @@ class BaseClient:
		msgbytes = message.encode()

		async with self._lock:
			# Set awaiting state for reply *before* sending, or currently active event
			# listeners will cause a race condition
			self._reply = awaiting = _ReplyState.AWAITING

			self.logger.debug("Sending: %s", repr(message))
			await self.sock.send(msgbytes)

			awaiting = _ReplyState.AWAITING
			self._reply = awaiting
			while self._reply is awaiting:
				await self._msg_notification()