Threaded IO: logging should be safe in I/O threads.

Potentially it is possible that we get interleaved writes, even if
serverLog() makes sure to write into a buffer and then use printf(), so
even this should be ok. However in general POSIX guarantees that writing
to the same file pointer object from multiple threads is safe. Anyway
currently we *reopen* the file at each call, but for the standard output
logging.

The logging functions actually also access global configuration while
performing the log (for instance in order to check the log level, the
log filename and so forth), however dunring the I/O threads execution
we cannot alter such shared state in any way.
This commit is contained in:
antirez 2019-04-08 13:12:10 +02:00
parent 8d7d2be24f
commit 463ccf8664

View File

@ -1174,14 +1174,13 @@ int writeToClient(int fd, client *c, int handler_installed) {
zmalloc_used_memory() < server.maxmemory) &&
!(c->flags & CLIENT_SLAVE)) break;
}
/* FIXME: Fixme, use atomic var for this. */
server.stat_net_output_bytes += totwritten;
if (nwritten == -1) {
if (errno == EAGAIN) {
nwritten = 0;
} else {
// serverLog(LL_VERBOSE,
// "Error writing to client: %s", strerror(errno));
serverLog(LL_VERBOSE,
"Error writing to client: %s", strerror(errno));
freeClientAsync(c);
return C_ERR;
}