Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions atat/src/blocking/simple_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ impl<'a, RW: Read + Write + ReadReady + WriteReady, D: Digester> SimpleClient<'a
// Write request
let until = Instant::now() + self.config.tx_timeout;
let mut pos = 0;
while pos < self.pos {
while pos < len {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loop does not seem right? While the change is correct (len instead of self.pos), the self.buf bound and the pos increment seems wrong?

I think it would be better to use self.rw.write_all(&self.buf[..len]) instead of hand-rolling it, unless you have a particular reason for hand-rolling the same?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right about that, I don't know how I missed that 😅.

The hand-rolling is necessary tho, write_ready signals that the next write will be block-free, but write_all may perform as many writes as it needs.
If we cannot add any check in-between write calls the timeout won't work and the client may get stuck indefinitely depending on the inner writer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, in that case pos += self.rw.write(&self.buf[pos..len]).or(Err(Error::Write))?;

wait_for_write(&mut self.rw, until)?;
self.rw.write(&self.buf[pos..]).or(Err(Error::Write))?;
pos += 1;
pos += self.rw.write(&self.buf[pos..len]).or(Err(Error::Write))?;
}

let until = Instant::now() + self.config.flush_timeout;
Expand Down Expand Up @@ -136,6 +135,8 @@ impl<RW: Read + ReadReady + Write + WriteReady, D: Digester> AtatClient
return cmd.parse(Ok(&[]));
}

self.pos = 0;

let timeout = Duration::from_millis(Cmd::MAX_TIMEOUT_MS.into());
let until = Instant::now() + timeout;
loop {
Expand Down
Loading