From 69c2358481e7b56ad295fc6303724f0649700e1c Mon Sep 17 00:00:00 2001 From: Eyal Kalderon Date: Sun, 9 Aug 2020 17:49:30 +0800 Subject: [PATCH] Fix subtle atomic increment bug introduced in #202 We must not increment the `request_id` counter if the server is not yet initialized, as this could result in client-to-server request IDs starting at a number other than 1, once the initialization process is complete. --- src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.rs b/src/client.rs index 2794ecd6..090560fd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -291,7 +291,7 @@ impl Client { if self.inner.initialized.load(Ordering::SeqCst) { self.send_request::(params).await } else { - let id = self.inner.request_id.fetch_add(1, Ordering::Relaxed); + let id = self.inner.request_id.load(Ordering::SeqCst) + 1; let msg = ClientRequest::request::(id, params); trace!("server not initialized, supressing message: {}", msg); Err(jsonrpc::not_initialized_error())