Skip to content

wil\winrt.h's wil::wait_for_completion_or_timeout_nothrow() returns 0x8000000e when it hits timeout #322

@elroychan

Description

@elroychan

I was digging into usage of wil::wait_for_completion_or_timeout_nothrow(), from wil\winrt.h
And was observing a strange behaviour, where it would clearly timeout, but it fails with 0x8000000e (E_ILLEGAL_METHOD_CALL) instead of success.

With this bug, I cannot properly do this logic:
DWORD threadTimeoutMs = 1000;
RETURN_IF_FAILED(wil::wait_for_completion_or_timeout_nothrow(asyncUpdateOp.get(), threadTimeoutMs, &bTimedOut));
RETURN_HR_IF(HRESULT_FROM_WIN32(ERROR_TIMEOUT), bTimedOut);

because it would always fail out with 0x8000000e, before letting me error out with ERROR_TIMEOUT.

I tracked it down to where WaitForCompletion would return S_OK with timedOut = true.
But the next line, GetResults() would fail because the operation was not completed yet, thus returning 0x8000000e.
template <typename TIOperation, typename TIResults>
HRESULT WaitForCompletion(In TIOperation operation, Out TIResults result, COWAIT_FLAGS flags,
DWORD timeoutValue, Out_opt bool* timedOut) WI_NOEXCEPT
{
RETURN_IF_FAILED_EXPECTED(details::WaitForCompletion(operation, flags, timeoutValue, timedOut));
return operation->GetResults(result);
}

The fix should be to check if (!timedOut) { return operation->GetResults(result); } else return S_OK;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions