Skip to content

Commit 69c2358

Browse files
committed
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.
1 parent 19b906f commit 69c2358

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl Client {
291291
if self.inner.initialized.load(Ordering::SeqCst) {
292292
self.send_request::<R>(params).await
293293
} else {
294-
let id = self.inner.request_id.fetch_add(1, Ordering::Relaxed);
294+
let id = self.inner.request_id.load(Ordering::SeqCst) + 1;
295295
let msg = ClientRequest::request::<R>(id, params);
296296
trace!("server not initialized, supressing message: {}", msg);
297297
Err(jsonrpc::not_initialized_error())

0 commit comments

Comments
 (0)