Skip to content

Commit

Permalink
Add seek needed to read a growing file on newer Perl versions.
Browse files Browse the repository at this point in the history
As of Perl 5.36, it appears that they have fixed the broken EOF handling and pgaudit_analyze will not continue to read the log after it parses it the first time. This means that it is unable to get any new log entries that are added to a file after it opens it the first time. To fix this, seek to the current position, which clears the EOF flag. See https://groups.google.com/g/linux.debian.bugs.dist/c/ZaxLI8YufO8 for details.

This specific issue was found because on Debian 12 (Bookworm) the default Perl version is now 5.36.0-7, which during our testing we found that the daemon was no longer updating. After debugging and thinking that the daemon was dying, we realized that if we started the daemon again it would update the analyze DB to the current state of the log files, but not get any new updates. After troubleshooting further, we found that it was related to the above bug and this small change appears to fix the issue.

We have tested various fixes and this one appears to be the least impactful on CPU utilization, but still resolves the issue in question.
  • Loading branch information
crunchyheath authored Aug 6, 2023
1 parent 8f03d09 commit af8873b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bin/pgaudit_analyze
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,12 @@ while(!$bDone)
$oLogCSV = new PgAudit::CSV({binary => 1, empty_is_undef => 1});
}

# Perl 5.36 fixed an issue where you could continue reading a file that was being appended to after hitting EOF, see:
# https://groups.google.com/g/linux.debian.bugs.dist/c/ZaxLI8YufO8. Therefore we must seek to the current location to
# continue reading if the log is being appended to.
seek($hFile, 0, 1)
or confess "unable to seek to current position in ${strLogPath}/${strLogFile}";

# Parse all rows in the file into CSV
while (my $stryRow = $oLogCSV->getline($hFile))
{
Expand Down

0 comments on commit af8873b

Please sign in to comment.