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

Prevent deadlock with BULK transfert and reduce log noise #13735

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

acolombier
Copy link
Member

@acolombier acolombier commented Oct 8, 2024

  • Set a timeout (currently 5sec) to prevent deadlock (occurred with the S4Mk3, as the device seems to have froze, leading to the Mixxx controller thread to starve.)
  • Make success log message only displayed when using --controller-debug

@JoergAtGithub
Copy link
Member

In #13622 we have a open discussion because of the interface number for bulk already

@acolombier
Copy link
Member Author

Ah yeah, completely forgot about that one. I guess we might still want to get that PR for timeout and error detection fix?

@JoergAtGithub
Copy link
Member

I think this one is not in conflict with #13622

@acolombier acolombier force-pushed the fix/bulk-use-iface-on-linux branch from dd7a5b9 to 6aa11ac Compare October 8, 2024 21:08
@acolombier
Copy link
Member Author

Realised that the signature change makes more sense to move into #13737 as it used in there to stop upon comm failure.

Repurposing the PR for only timeout and spamming log messages

@acolombier acolombier changed the title fix: use interface number on Linux and improve logs Prevent deadlock with BULK transfert and reduce log noise Oct 8, 2024
src/controllers/bulk/bulkcontroller.cpp Outdated Show resolved Hide resolved
src/controllers/bulk/bulkcontroller.cpp Outdated Show resolved Hide resolved
src/controllers/bulk/bulkcontroller.cpp Outdated Show resolved Hide resolved
@acolombier acolombier force-pushed the fix/bulk-use-iface-on-linux branch from 1c2e7bc to 74de707 Compare October 10, 2024 19:13
@acolombier
Copy link
Member Author

@Swiftb0y the code suggestion doesn't seem to work. Any suggestion to fix it?

#include "util/time.h"
#include "util/trace.h"

namespace {
using namespace std::literals;
constexpr std::seconds kBulkSendTimeout = 5s;
Copy link
Member

Choose a reason for hiding this comment

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

I think it is:

    using namespace std::literals::chrono_literals; 
    constexpr std::chrono::seconds kBulkSendTimeout = 5s;

However the struggle here, confirms IMHO that using 5s is a bit over engineered here when not using this for chronio functions. So I would release the compiler from some work and use use the libusb type without a cast:

constexpr unsigned int kBulkSendTimeoutMs = 5000;

The Ms prefix documents the value unit.
Both is fine for me.

Copy link
Member

Choose a reason for hiding this comment

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

I disagree honestly. The added compile time is negligible. This is about avoiding primitive obsession.

Copy link
Member Author

Choose a reason for hiding this comment

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

The resource you linked make sense, but in our case, we don't own the API and simply must comply to libusb asking for a tasteless uint.
To be honest, I'm leaning towards @daschuer's suggestion as I find it more readable - std::milliseconds(kBulkSendTimeout).count() feels a bit cryptic to me (had to go to the std lib to see what count was doing). Appreciate you are trying to roll out std on time within the Mixxx API tho so can't make up my mind.
Would a @mixxxdj/developers help us with the tie here?

Copy link
Member

Choose a reason for hiding this comment

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

In general I'm in favor for these literal types, and we should all get common to this std C++ syntax, as libraries like Qt convert their timing types towards this standard.
In this case, the literal type give us no type safety, as it's converted to the raw integer type before use.
Regarding readability, where a const value is only used once in the whole code - inline with the unit as comment is IMHO the most readable style:

c_function(5000, // Send timeout in milliseconds
           otherArgument); 

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @JoergAtGithub , that does sound like a great middle ground. @daschuer @Swiftb0y happy with that option?

Copy link
Member

@Swiftb0y Swiftb0y Oct 12, 2024

Choose a reason for hiding this comment

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

In this case, the literal type give us no type safety, as it's converted to the raw integer type before use.

Yeah thats unfortunate, but the conversion is done at the API boundary (so its like calling .get() on a unique_ptr when passing to a C API). Its also easier (in theory/general) to upgrade to the newer API if the conversion is done here, but since this is a C API, that will never happen. I still prefer my original solution (an unnamed constant is not much better), but I won't insist on it. Just my two cents for what is best in the general case. This is only a one-off so as you rightfully pointed out, it doesn't make much difference. I'm fine with anything in this particular case.

Copy link
Member

Choose a reason for hiding this comment

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

As I already mentioned, all suggestions are fine for me as well.

I can confirm the original request of @Swiftb0y to replace a comment by code.

Comment difficult code, but avoid comments by making the code itself expressive when possible.

@acolombier acolombier force-pushed the fix/bulk-use-iface-on-linux branch 2 times, most recently from fbd5fe5 to 1d1a5e9 Compare October 11, 2024 08:04
@Swiftb0y
Copy link
Member

whoops, yeah. Its std::chrono::unit.

#include <chrono>

using namespace std::literals; 
constexpr std::chrono::seconds kBulkSendTimeout = 5s;

int usage() {
    return std::chrono::milliseconds(kBulkSendTimeout).count();
}

Copy link
Member

@Swiftb0y Swiftb0y left a comment

Choose a reason for hiding this comment

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

not blocking this any further. please fix pre-commit and clang-tidy and then its LGTM.

@acolombier acolombier force-pushed the fix/bulk-use-iface-on-linux branch from 683fac2 to 0053ca0 Compare October 13, 2024 19:34
Copy link
Member

@Swiftb0y Swiftb0y left a comment

Choose a reason for hiding this comment

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

🤷

@acolombier acolombier requested a review from daschuer October 13, 2024 21:31
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.

Thank you.LGTM

@daschuer daschuer merged commit 60abf58 into mixxxdj:main Oct 14, 2024
13 checks passed
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.

4 participants