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

Issue with log purging when FileChannel compression is enabled #2439

Closed
sdaly2107 opened this issue Aug 28, 2018 · 7 comments · Fixed by #4417
Closed

Issue with log purging when FileChannel compression is enabled #2439

sdaly2107 opened this issue Aug 28, 2018 · 7 comments · Fixed by #4417
Assignees

Comments

@sdaly2107
Copy link

sdaly2107 commented Aug 28, 2018

Expected behavior

Expect that rotated log count is consistent when compression enabled.

Actual behavior

When FileChannel compression is enabled, we sometimes see too many files being retained, or too little. Issues occurs around 1 in 20 runs.

Steps to reproduce the problem

-Open new FileChannel (flush false, 1 M rotation, 3 purge count, archive timestamp, times local, compress true)
-Log x1024 1Kb messages 5 times
-Close fine channel
-Expected current log and 3 compressed archives - actually sometimes seeing 2 archives, and sometimes 5

Example code to reproduce -

static const uint32_t MAX_ROLLOVER_TIMES = 5;
static const uint32_t LONG_MESSAGE_LENGTH = 1024;
static const uint32_t LONG_MAX_FILESIZE = 1024;

std::vector<uint8_t> longMessage(LONG_MESSAGE_LENGTH, 0x40);
longMessage.push_back(0);

Poco::Path logsPath(Poco::Path::current(), "logs");
Poco::File logsDir(logsPath.toString());
logsDir.createDirectory();
logsPath.append("test.log");


Poco::AutoPtr<Poco::FileChannel> fileChannel = new Poco::FileChannel("ABC");
fileChannel->setProperty(Poco::FileChannel::PROP_PATH, logsPath.toString());
fileChannel->setProperty(Poco::FileChannel::PROP_FLUSH, "false");
fileChannel->setProperty(Poco::FileChannel::PROP_ROTATION, "1 M");
fileChannel->setProperty(Poco::FileChannel::PROP_PURGECOUNT, "3");
fileChannel->setProperty(Poco::FileChannel::PROP_ARCHIVE, "timestamp");
fileChannel->setProperty(Poco::FileChannel::PROP_TIMES, "local");
fileChannel->setProperty(Poco::FileChannel::PROP_COMPRESS, "true");

fileChannel->open();


std::string text(longMessage.begin(), longMessage.end());

for (uint32_t i = 1; i <= MAX_ROLLOVER_TIMES; ++i)
{
    for (uint32_t j = 0; j < LONG_MAX_FILESIZE; ++j)
    {
        Poco::Message message("ABC", text, Poco::Message::PRIO_INFORMATION);
        fileChannel->log(message);
    }

}

Poco::Thread::sleep(2000);
fileChannel->close();

POCO version

1.7.9

Compiler and version

VS2017 / v141

Operating system and version

Windows 10

Other relevant information

@preranamkhare
Copy link

Hi,
Is this issue fixed for linux platform and if yes which version ?

@github-actions
Copy link

This issue is stale because it has been open for 365 days with no activity.

@github-actions github-actions bot added the stale label Jun 26, 2022
@aleks-f aleks-f added this to the Release 1.13.0 milestone Jun 26, 2022
@aleks-f aleks-f removed the stale label Jun 26, 2022
@aleks-f aleks-f self-assigned this Oct 26, 2023
@aleks-f aleks-f assigned matejk and unassigned aleks-f Dec 21, 2023
@aleks-f aleks-f added this to 1.13 Jan 14, 2024
@matejk matejk added the bug label Jan 17, 2024
@matejk
Copy link
Contributor

matejk commented Jan 17, 2024

Hi, Is this issue fixed for linux platform and if yes which version ?

@preranamkhare, do you get this issue in Linux. It was reported for Windows.

@matejk
Copy link
Contributor

matejk commented Jan 22, 2024

Reproducible with Poco 1.13 on macOS 14.2.

@matejk matejk moved this to In Progress in 1.13 Jan 22, 2024
@matejk
Copy link
Contributor

matejk commented Jan 22, 2024

Root of the problem is that renaming, deletion and creating compressed files is handled independently in two threads inside ArchiveStrategy.cpp (compressImpl and moveFile).

The situation is even worse with numbered files because it is more likely that compression will try to process one of the files that is being renamed due to log rotation.

@matejk
Copy link
Contributor

matejk commented Jan 24, 2024

@aleks-f, @obiltschnig:

I see two possibilities to solve this issue:

  • Introduce locking between renaming files and compression that also handles file names
  • Perform log rotation after compression finishes with a new ActiveDispatcher in some way and serialise execution of those two
    • When compression is not enabled, only rotation dispatcher would be used

@matejk
Copy link
Contributor

matejk commented Jan 25, 2024

Additional investigation shows that PurgeStrategy would have to be synchronised with log file rotation and compression.

@matejk matejk linked a pull request Jan 25, 2024 that will close this issue
@aleks-f aleks-f removed this from 1.13 Jan 30, 2024
@aleks-f aleks-f added this to 1.14 Jan 30, 2024
@matejk matejk moved this to In Progress in 1.14 Feb 1, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in 1.14 Feb 1, 2024
@matejk matejk added the fixed label Feb 1, 2024
@matejk matejk reopened this Feb 1, 2024
@matejk matejk closed this as completed Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants