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

Fix race condtion that cause corrupted tail of output TS #875

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

moveman
Copy link
Contributor

@moveman moveman commented May 9, 2024

We found that occasioinally the tail of the TS output is corrupted. After some debugging and guessing, the problem should be caused by this code

m_nothingToExecute = m_writeQueue.empty();

This code is not atomic. It is equivalent to this:

bool flag = m_writeQueue.empty();
m_nothingToExecute = flag;

Other threads could jump in after the first line and before the second line.
This includes BufferedFileWriter::addWriterData(). When addWriteData() is indeed be called,
the situation will be like this:

bool flag = m_writeQueue.empty(); // (true)

  m_nothingToExecute = false;
  m_writeQueue.push(data);

m_nothingToExecute = flag; // (true)

writeQueue is inserted a data and is NOT empty; however, m_nothingToExecute is set to true by the final line.
That will cause waitForWriting() to return and then close() is called before the remaining byte is flushed to the output.

@ValeZAA
Copy link

ValeZAA commented May 25, 2024

Can you provide a sample source file and output: before and after?

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

Successfully merging this pull request may close these issues.

None yet

2 participants