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 conditions between caching reader and worker (again) #2308

Closed
wants to merge 6 commits into from
Closed

Fix race conditions between caching reader and worker (again) #2308

wants to merge 6 commits into from

Conversation

uklotzde
Copy link
Contributor

Even more serious race conditions and design flaws.

I've also reverted some unintended renamings from the previous PR, sorry for the noise.

@uklotzde uklotzde added this to the 2.2.3 milestone Sep 30, 2019
@uklotzde
Copy link
Contributor Author

On master the following debug assertion triggered while loading a track:

Critical [Engine]: DEBUG ASSERT: "m_trackSampleRateOld && m_tempo_ratio_old" in function void EngineBuffer::updateIndicators(double, int) at src/engine/enginebuffer.cpp:1205

@Be-ing
Copy link
Contributor

Be-ing commented Sep 30, 2019

I think we should hold off on releasing 2.2.3 for a bit until we're confident all these recent changes to CachingReader are working.

On master the following debug assertion triggered while loading a track:

see #2235

@uklotzde
Copy link
Contributor Author

uklotzde commented Oct 1, 2019

The tests seem to fail because they don't keep an event loop running, although they expect signals to arrive. This does not work for queued connections. Looks like the test framework is insufficient for testing a correct implementation?

At some point I have to stop, this is getting completely out of control.

@uklotzde
Copy link
Contributor Author

uklotzde commented Oct 1, 2019

...and now MockedEngineBackendTest gets stuck.

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I need to do some manual tests tonight. What was the debug assertion you are trying to solve? What is the race condition you experience? It is a real issue?

// Handle signals from worker thread
connect(&m_worker,
&CachingReaderWorker::trackLoaded,
this,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work without a direct connection?
Do we have a Qt Main Loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't have an event loop then we must not use signals. Period.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

src/engine/cachingreader.cpp Outdated Show resolved Hide resolved
@daschuer
Copy link
Member

daschuer commented Oct 1, 2019

I got a debug asserting in CachingReader caused by the latest commit...

Can you recall which assertion has failed? I still see no non my system. Did it occur in the 2.2 or master branch?

DEBUG_ASSERT(m_state != State::Idle); in process(). But don't expect this to be reproducible. The whole design was thread-unsafe. I noticed this only at a closer look, although I had revisited and fixed the code in this class multiple times.

}

void CachingReader::process() {
ReaderStatusUpdate update;
while (m_stateFIFO.read(&update, 1) == 1) {
while (m_readerStatusUpdateFIFO.read(&update, 1) == 1) {
DEBUG_ASSERT(m_state != State::Idle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion may occur after ejecting a track and loading a new one.
Was this the one you have experienced?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments to the wrong/closed PR: #2305 (review)

This is the debug assertion that helped me discover the race condition. I refuse to remove it because it is correct unless someone provides a counterexample.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have checked the old version in 3e9e2ae before the fixes and I still don't see a reason why this debug assertion is not valid?

@uklotzde
Copy link
Contributor Author

uklotzde commented Oct 2, 2019

MpscFifo is a backported from the multi-threaded analysis.

@uklotzde
Copy link
Contributor Author

uklotzde commented Oct 2, 2019

The whole design is broken and slots/signals are used incorrectly. CachingReader lives the main thread, receives signals from a worker thread and process()/read() are called from an engine thread.

I surrender.

@uklotzde uklotzde closed this Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants