Skip to content

Commit

Permalink
Fix subtle atomic increment bug introduced in #202
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ebkalderon committed Aug 9, 2020
1 parent 19b906f commit 69c2358
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl Client {
if self.inner.initialized.load(Ordering::SeqCst) {
self.send_request::<R>(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::<R>(id, params);
trace!("server not initialized, supressing message: {}", msg);
Err(jsonrpc::not_initialized_error())
Expand Down

0 comments on commit 69c2358

Please sign in to comment.