-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
DeviceIoControl use async mode #1127
base: master
Are you sure you want to change the base?
Conversation
Please help to explain the background of this pull request and what is the issue you are trying to address. What is the configuration of your system and how long is "long time" for your system? |
we use libusb to get the bandwidth of the usb camera.In our application,our user report they will always block when call "DeviceIoControl " in the windows_winusb.c file. DeviceIoControl function execution keeps blocking.“long time” means forever. |
Thanks for the updates. The user's system seem to be pretty decent and not a slow system. |
How's the code review going ? Can you approve? |
Unfortunately I am not a developer (mainly on testing and support side of libusb project) and I will not be able to review properly for more complex patch like this one. And right now we do not have a real Windows developer to look into the patches, so you may have to be patient. |
Interestingly that this pull request seems to fix #1136. Updates: it seems to fix $1163 as well. |
@weishaodi2zss Please help to fix the warning that not all commits were signed. Thanks. There is a warning from github.
Edit: please ignore this request. It is not necessary. |
we find some side effects in our product,the commit will fix the side effect,please approve the pr,the pr have been applied our application which have more than 6000000 users and it work well in our application. Thanks you for following my PR. |
@tormodvolden How do you like this pull request? I think it is probably okay to be merged. |
I don't understand enough of this to approve it. That there are still fixes coming in also means we shouldn't rush it. Why is the DeviceIoControl blocking indefinitely in the first place? I would be fine with including a workaround for a kernel driver issue, but the issue must then be fully understood and documented. I understand the patch uses overlapping I/O to implement a timeout, but e.g. why is 1s better than 10 s or 0.1s? |
@weishaodi2zss |
@tormodvolden and @weishaodi2zss Another possibility is to add an new option to |
What is the libusb function causing this? EDIT: Looking at the suggest code change it seems to be the enumeration in libusb_init(). So which of these DeviceIoControl()'s are actually hanging? Maybe only one of them? |
HIDAPI uses async
I don't think that should be required. |
Meanwhile, @weishaodi2zss do you mind fixing the conflict? |
Take some time to continue reviewing the code here @Youw |
|
||
error = GetLastError(); | ||
if (error != ERROR_IO_PENDING) { | ||
CancelIo(hDevice); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be:
CancelIo(hDevice); | |
CancelIoEx(hDevice, &overlapped); |
?
|
||
DWORD wret = WaitForSingleObject(event, IO_WAIT_TIME); | ||
if (wret != WAIT_OBJECT_0) { | ||
CancelIo(hDevice); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as prev comment
assert(bytes_written == *lpBytesReturned); | ||
|
||
if (!ret) { | ||
CancelIo(hDevice); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we're here - WaitForSingleObject
has returned the WAIT_OBJECT_0
, which means there is no pending operations this function has started
probably best not to interfere with other IO operations that might be happening on the device
CancelIo(hDevice); |
|
||
priv = usbi_get_device_priv(dev); | ||
|
||
// If the device is already initialized, we can stop here | ||
if (priv->initialized) | ||
return LIBUSB_SUCCESS; | ||
|
||
io_event = CreateEvent(NULL, FALSE, FALSE, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicitly use either CreateEventA
or CreateEventW
to be consistent with other places, e.g. CreateFileA
|
||
priv = usbi_get_device_priv(dev); | ||
|
||
// If the device is already initialized, we can stop here | ||
if (priv->initialized) | ||
return LIBUSB_SUCCESS; | ||
|
||
io_event = CreateEvent(NULL, FALSE, FALSE, NULL); | ||
if (!io_event || io_event == INVALID_HANDLE_VALUE) return LIBUSB_ERROR_IO; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
if (!io_event || io_event == INVALID_HANDLE_VALUE) return LIBUSB_ERROR_IO; | |
if (io_event == NULL || io_event == INVALID_HANDLE_VALUE) return LIBUSB_ERROR_IO; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excuse me for long delays in the review. I'm having too much on my plate recently.
Functionally I think this is perfectly fine (except my latest comments).
@weishaodi2zss what is the best way to check this out? Maybe @mcuee (or someone else) could try it locally. I'm mostly conserned that all the positive scenarios should continue function as ther where (i.e. nothing breaks after this change).
I'd like to carry out some tests on this. It will be good to sync up with git master first though. |
As of now,
Debug log for |
For testing you can also rebase this locally:
|
This seems to kinda "fix" my issue in #1163 I believe the reason why it takes so long is because with the faulty controller connected every single device runs into the timeout of 2 seconds for some reason. |
Thanks. Here is the new log, still the same issues.
|
BTW, this has nothing to do with the external Dell Type C docking edition and external Ugreen USB Hub. Even with minimum setup (just the laptop, plus one USB mouse dongle and a headset), the issue is already there.
|
DeviceIoControl maybe block in long time,we use async mode to control DeviceIoControl wait time.