Skip to content

Commit

Permalink
Fix bug in writeToClient (valkey-io#834)
Browse files Browse the repository at this point in the history
Fix bug in writeToClient
In valkey-io#758, a major refactor was
done to `networking.c`.

As part of this refactor, a new bug was introduced: we don't advance the
`c->buf` pointer in repeated writes.

This bug should be very unlikely to manifest, as it requires the
client's TCP buffer to be filled in the first try and then released
immediately after in the second try.

Despite all my efforts to reproduce this scenario, I was unable to do
so.

Signed-off-by: Uri Yagelnik <[email protected]>
Signed-off-by: mwish <[email protected]>
  • Loading branch information
uriyage authored and mapleFU committed Aug 22, 2024
1 parent c59c948 commit 4e8f4a3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -2092,7 +2092,7 @@ int _writeToClient(client *c) {
ssize_t tot_written = 0;

while (tot_written < bytes_to_write) {
int nwritten = connWrite(c->conn, c->buf + c->sentlen, bytes_to_write - tot_written);
int nwritten = connWrite(c->conn, c->buf + c->sentlen + tot_written, bytes_to_write - tot_written);
if (nwritten <= 0) {
c->write_flags |= WRITE_FLAGS_WRITE_ERROR;
tot_written = tot_written > 0 ? tot_written : nwritten;
Expand Down

0 comments on commit 4e8f4a3

Please sign in to comment.