Skip to content

Commit aa7f7ea

Browse files
committed
session: wait for protocol ver negotiation to finish before other reqs
We already enforce that server.version must be the first received message in a session, but we also need to ensure that the server finishes processing that message and sets up the correct protocol version before starting to process further messages.
1 parent 93afd36 commit aa7f7ea

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/electrumx/server/session.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ def __init__(
965965
self.coin = self.env.coin
966966
self.client = 'unknown'
967967
self.sv_seen = False # has seen 'server.version' message?
968+
self.sv_negotiated = asyncio.Event() # done negotiating protocol version
968969
self.anon_logs = self.env.anon_logs
969970
self.txs_sent = 0
970971
self.log_me = SessionBase.log_new
@@ -1034,6 +1035,9 @@ async def handle_request(self, request):
10341035
await self._do_crash_old_electrum_client()
10351036
raise ReplyAndDisconnect(RPCError(
10361037
BAD_REQUEST, f'use server.version to identify client'))
1038+
# Wait for version negotiation to finish before processing other messages.
1039+
if method != 'server.version' and not self.sv_negotiated.is_set():
1040+
await self.sv_negotiated.wait()
10371041

10381042
self.session_mgr._method_counts[method] += 1
10391043
coro = handler_invocation(handler, request)()
@@ -1525,6 +1529,7 @@ async def server_version(self, client_name='', protocol_version=None):
15251529
BAD_REQUEST, f'unsupported protocol version: {protocol_version}'))
15261530
self.set_request_handlers(ptuple)
15271531

1532+
self.sv_negotiated.set()
15281533
return electrumx.version, self.protocol_version_string()
15291534

15301535
async def transaction_broadcast(self, raw_tx):
@@ -1700,6 +1705,7 @@ class LocalRPC(SessionBase):
17001705
def __init__(self, *args, **kwargs):
17011706
super().__init__(*args, **kwargs)
17021707
self.sv_seen = True
1708+
self.sv_negotiated.set()
17031709
self.client = 'RPC'
17041710
self.connection.max_response_size = 0
17051711

0 commit comments

Comments
 (0)