microsoft / microsoft/wil

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

Open
#322 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
3k
Forks
300
Avg merge
19h 12m
Merged PRs (30d)
1

Description

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;

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in wil\winrt.h at WaitForCompletion and trace how details::WaitForCompletion sets timedOut before GetResults is called. Reproduce a timeout with wil::wait_for_completion_or_timeout_nothrow(), then verify that a timed-out operation returns success with timedOut set and does not call GetResults.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
operating-systems
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.