You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by br...@apache.org on 2014/05/21 20:05:42 UTC
git commit: [TS-2822] Crash in LogBufferIterator::next
Repository: trafficserver
Updated Branches:
refs/heads/master 8fc92c4c8 -> 13453d9ab
[TS-2822] Crash in LogBufferIterator::next
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/13453d9a
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/13453d9a
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/13453d9a
Branch: refs/heads/master
Commit: 13453d9ab8c975fd12da632a49868eeaf2eb1fd3
Parents: 8fc92c4
Author: Brian Geffon <br...@apache.org>
Authored: Wed May 21 11:05:35 2014 -0700
Committer: Brian Geffon <br...@apache.org>
Committed: Wed May 21 11:05:35 2014 -0700
----------------------------------------------------------------------
proxy/logstats.cc | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/13453d9a/proxy/logstats.cc
----------------------------------------------------------------------
diff --git a/proxy/logstats.cc b/proxy/logstats.cc
index 15aeaa2..5d07df1 100644
--- a/proxy/logstats.cc
+++ b/proxy/logstats.cc
@@ -1730,7 +1730,7 @@ process_file(int in_fd, off_t offset, unsigned max_age)
unsigned second_read_size = sizeof(LogBufferHeader) - first_read_size;
nread = read(in_fd, &buffer[first_read_size], second_read_size);
if (!nread || EOF == nread) {
- Debug("logstats", "Second read of header failed (attemped %d bytes at offset %d, got nothing).", second_read_size, first_read_size);
+ Debug("logstats", "Second read of header failed (attemped %d bytes at offset %d, got nothing), errno=%d.", second_read_size, first_read_size, errno);
return 1;
}
@@ -1746,11 +1746,30 @@ process_file(int in_fd, off_t offset, unsigned max_age)
return 1;
}
- nread = read(in_fd, &buffer[sizeof(LogBufferHeader)], buffer_bytes);
- if (!nread || EOF == nread) {
- Debug("logstats", "Failed to read buffer payload [%d bytes]", buffer_bytes);
- return 1;
- }
+ const int MAX_READ_TRIES = 5;
+ int total_read = 0;
+ int read_tries_remaining = MAX_READ_TRIES; // since the data will be old anyway, let's only try a few times.
+ nread = 0;
+ do {
+ nread = read(in_fd, &buffer[sizeof(LogBufferHeader) + total_read], buffer_bytes - total_read);
+ if (EOF == nread) { // just bail on error
+ Debug("logstats", "Read failed while reading log buffer, wanted %d bytes, nread=%d, errno=%d", buffer_bytes - total_read, nread, errno);
+ return 1;
+ } else {
+ total_read += nread;
+ }
+
+ if (total_read < buffer_bytes) {
+ if (--read_tries_remaining <= 0) {
+ Debug("logstats_failed_retries", "Unable to read after %d tries, total_read=%d, buffer_bytes=%d", MAX_READ_TRIES, total_read, buffer_bytes);
+ return 1;
+ }
+ // let's wait until we get more data on this file descriptor
+ Debug("logstats_partial_read", "Failed to read buffer payload [%d bytes], total_read=%d, buffer_bytes=%d, tries_remaining=%d",
+ buffer_bytes - total_read, total_read, buffer_bytes, read_tries_remaining);
+ usleep(50*1000); // wait 50ms
+ }
+ } while (total_read < buffer_bytes);
// Possibly skip too old entries (the entire buffer is skipped)
if (header->high_timestamp >= max_age) {