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

8267819: CoInitialize/CoUninitialize should be called on same thread #521

Closed
wants to merge 1 commit into from

Conversation

sashamatveev
Copy link
Member

@sashamatveev sashamatveev commented May 27, 2021

JDK-8264737 introduced new code for audio device removal/arrival notifications which calls CoInitialize/CoUninitialize on separate threads. CoInitialize/CoUninitialize should be called on same thread, since initialization is per thread. Doing it on separate thread will result in unloading COM libraries on that thread and if it uses COM libraries it might not work correctly. Fixed by calling it on same thread in same way it is done in dshowwrapper.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8267819: CoInitialize/CoUninitialize should be called on same thread

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jfx pull/521/head:pull/521
$ git checkout pull/521

Update a local copy of the PR:
$ git checkout pull/521
$ git pull https://git.openjdk.java.net/jfx pull/521/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 521

View PR using the GUI difftool:
$ git pr show -t 521

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jfx/pull/521.diff

@bridgekeeper
Copy link

bridgekeeper bot commented May 27, 2021

👋 Welcome back almatvee! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Ready for review label May 27, 2021
@mlbridge
Copy link

mlbridge bot commented May 27, 2021

Webrevs

@kevinrushforth
Copy link
Member

/reviewers 2

@openjdk
Copy link

openjdk bot commented May 27, 2021

@kevinrushforth
The number of required reviews for this PR is now set to 2 (with at least 1 of role reviewers).

Copy link
Member

@kevinrushforth kevinrushforth left a comment

Choose a reason for hiding this comment

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

Looks good, and I think it's cleaner this way too. Two questions:

  1. Have you verified that it still works correctly on RDP reconnect?
  2. This isn't really related to your fix, since the logic for this part is the same before and after, should the rest of the Init method be short-circuited if CoInitialize fails?

@sashamatveev
Copy link
Member Author

  1. Yes, I did test it on RDP reconnect for multiple streams.
  2. Not really needed. CoCreateInstance() will fails in this case most likely and we will return false from Init(). So, it should be fine if it fails. Also, CoInitialize() can return RPC_E_CHANGED_MODE if someone already initialized thread as multithread apartment (MTA) and in this case CoCreateInstance() should work, so it is better not to fail Init() even if CoInitialize() failed.

bool bCallCoUninitialize = true;
bool bResult = false;

if (FAILED(CoInitialize(NULL))) {
Copy link
Member

Choose a reason for hiding this comment

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

As per the CoUninitialize doc, CoUninitialize should also be called if CoInitialize returns S_FALSE.
Can you please check.

Copy link
Member Author

Choose a reason for hiding this comment

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

It will be called. S_FALSE is not a failure and defined as 1. FAILED macro returns true if error code < 0.

Copy link
Member

@arapte arapte left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@openjdk
Copy link

openjdk bot commented Jun 3, 2021

@sashamatveev This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8267819: CoInitialize/CoUninitialize should be called on same thread

Reviewed-by: kcr, arapte

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 2 new commits pushed to the master branch:

  • 526f990: 8239138: StyleManager should use a BufferedInputStream
  • 5e6d442: 8267892: Add .gitattributes to repo

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Ready to be integrated label Jun 3, 2021
@sashamatveev
Copy link
Member Author

/integrate

@openjdk openjdk bot closed this Jun 3, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Ready to be integrated rfr Ready for review labels Jun 3, 2021
@openjdk
Copy link

openjdk bot commented Jun 3, 2021

@sashamatveev Since your change was applied there have been 2 commits pushed to the master branch:

  • 526f990: 8239138: StyleManager should use a BufferedInputStream
  • 5e6d442: 8267892: Add .gitattributes to repo

Your commit was automatically rebased without conflicts.

Pushed as commit 47700d8.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants