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

document QtCollider:LangClient - event loop deadlock issue #5039

Merged
merged 1 commit into from
Jul 1, 2020

Conversation

gurk
Copy link
Contributor

@gurk gurk commented Jun 27, 2020

In qt tick event handler there's potential for language deadlock with a recursive event loop call.
This fix uses trylock to bail early from handler when unable to obtain language lock.

e.g. deadlock can happen when tick called during work event handling, which is rare but possible.

Solution seems not too radical as SuperCollider appears to have precedence of this approach:

SC_LanguageClient::tick
SCApp AppClock handler

Tested with no apparent issues on MacOS 10.14.6.

Purpose and Motivation

Document the cause of #1640

Types of changes

  • Bug fix

To-do list

  • Code is tested
  • All tests are passing
  • Updated documentation
  • This PR is ready for review

@dyfer dyfer added comp: sclang sclang C++ implementation (primitives, etc.). for changes to class lib use "comp: class library" qt5 labels Jun 29, 2020
@mossheim
Copy link
Contributor

thanks! after looking at this more closely i think we should fix it in hidapi, per this comment, instead of here. the reason is that with this change we open the door to other multithreaded programming errors, some of which may be difficult to catch, whereas deadlock is easy to spot and fix with a backtrace. i think it is reasonable, in fact desirable, to continue to enforce that a tick in the language does not occur while interpreting command-line code.

@mossheim
Copy link
Contributor

our fork of hidapi, which you should submit a PR against directly, is here: https://github.com/supercollider/hidapi

as far as i know the signal11 repo is unmaintained now.

@gurk
Copy link
Contributor Author

gurk commented Jul 1, 2020

Brian, thank you for your consideration and comments.



My original intention was to fix hidapi, but as time passed it seemed worthwhile to investigate other solutions.

This PR seemed like a good approach when trylock worked and found it used in older code, esp. doClockTask method from scapp (cocoa tick equivalent).

However, I agree with your concern, and think changing a critical code path to fix an edge case is probably not worthwhile.

Could it make sense to comment point of deadlock?

Maybe make design a little more apparent.

e.g.

void LangClient::tick() {
    double secs;


    lock();
    // deadlock here indicates behaviour which likely should be avoided.
    // e.g. calling qt event loop from primitive.

    bool haveNext = tickLocked(&secs);
    unlock();

@mossheim
Copy link
Contributor

mossheim commented Jul 1, 2020

Could it make sense to comment point of deadlock?

Maybe make design a little more apparent.

yeah! that would be really helpful actually.

@gurk gurk force-pushed the topic/qt_event_loop_fix branch from 09edd79 to 14f368b Compare July 1, 2020 04:06
@gurk
Copy link
Contributor Author

gurk commented Jul 1, 2020

Is this pull request okay, or shall I make a new one?

Copy link
Contributor

@mossheim mossheim left a comment

Choose a reason for hiding this comment

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

thanks!

@mossheim
Copy link
Contributor

mossheim commented Jul 1, 2020

@gurk no new PR needed, i'll merge this as is. and also edit the PR title so it accurately reflects the purpose. thanks!

@mossheim mossheim merged commit da9eb8c into supercollider:develop Jul 1, 2020
@mossheim mossheim changed the title QtCollider:LangClient - event loop deadlock fix - issue #1640 document QtCollider:LangClient - event loop deadlock issue Jul 1, 2020
@patrickdupuis patrickdupuis mentioned this pull request Jul 5, 2020
4 tasks
mossheim added a commit that referenced this pull request Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: sclang sclang C++ implementation (primitives, etc.). for changes to class lib use "comp: class library" qt5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants