Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r->io.file.buffered is incorrect in function 'rioFileWrite' #4322

Open
chenkline opened this issue Sep 21, 2017 · 2 comments
Open

r->io.file.buffered is incorrect in function 'rioFileWrite' #4322

chenkline opened this issue Sep 21, 2017 · 2 comments

Comments

@chenkline
Copy link

// Original code :
static size_t rioFileWrite(rio *r, const void *buf, size_t len) {
size_t retval;

retval = fwrite(buf,len,1,r->io.file.fp);
r->io.file.buffered += len;

if (r->io.file.autosync &&
    r->io.file.buffered >= r->io.file.autosync)
{
    fflush(r->io.file.fp);
    aof_fsync(fileno(r->io.file.fp));
    r->io.file.buffered = 0;
}
return retval;

}

this line:
r->io.file.buffered += len;

should be:
if ( retval >= 0 ) {
r->io.file.buffered += retval ;
}

@antirez
Copy link
Contributor

antirez commented Sep 21, 2017

Hello, yes @chenkline your fix looks correct to me. Just a question, did you find this bug in real world scenarios or is just an analysis you are doing in the Redis code? Because it looks like that when the fwrite() call failed, anyway the underlying RIO process aborted, so this change does not remove any real world bug. It's important to me to understand if a given bug also had real-world effects or not. Thanks.

@chenkline
Copy link
Author

it's not in real world scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants