Skip to content

Commit

Permalink
8294699: Launcher causes lingering busy cursor
Browse files Browse the repository at this point in the history
Reviewed-by: almatvee
  • Loading branch information
Alexey Semenyuk committed Dec 5, 2023
1 parent fddc02e commit d3df3eb
Showing 1 changed file with 78 additions and 2 deletions.
80 changes: 78 additions & 2 deletions src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -150,6 +150,82 @@ void addCfgFileLookupDirForEnvVariable(
}


class RunExecutorWithMsgLoop {
public:
static DWORD apply(const Executor& exec) {
RunExecutorWithMsgLoop instance(exec);

UniqueHandle threadHandle = UniqueHandle(CreateThread(NULL, 0, worker,
static_cast<LPVOID>(&instance), 0, NULL));
if (threadHandle.get() == NULL) {
JP_THROW(SysError("CreateThread() failed", CreateThread));
}

MSG msg;
BOOL bRet;
while((bRet = GetMessage(&msg, instance.hwnd, 0, 0 )) != 0) {
if (bRet == -1) {
JP_THROW(SysError("GetMessage() failed", GetMessage));
} else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

// Wait for worker thread to terminate to guarantee it will not linger
// around after the thread running a message loop terminates.
const DWORD res = ::WaitForSingleObject(threadHandle.get(), INFINITE);
if (WAIT_FAILED == res) {
JP_THROW(SysError("WaitForSingleObject() failed",
WaitForSingleObject));
}

LOG_TRACE(tstrings::any()
<< "Executor worker thread terminated. Exit code="
<< instance.exitCode);
return instance.exitCode;
}

private:
RunExecutorWithMsgLoop(const Executor& v): exec(v) {
exitCode = 1;

// Message-only window.
hwnd = CreateWindowEx(0, _T("STATIC"), _T(""), 0, 0, 0, 0, 0,
HWND_MESSAGE, NULL, GetModuleHandle(NULL), NULL);
if (!hwnd) {
JP_THROW(SysError("CreateWindowEx() failed", CreateWindowEx));
}
}

static DWORD WINAPI worker(LPVOID param) {
static_cast<RunExecutorWithMsgLoop*>(param)->run();
return 0;
}

void run() {
JP_TRY;
exitCode = static_cast<DWORD>(exec.execAndWaitForExit());
JP_CATCH_ALL;

JP_TRY;
if (!PostMessage(hwnd, WM_QUIT, 0, 0)) {
JP_THROW(SysError("PostMessage(WM_QUIT) failed", PostMessage));
}
return;
JP_CATCH_ALL;

// All went wrong, PostMessage() failed. Just terminate with error code.
exit(1);
}

private:
const Executor& exec;
DWORD exitCode;
HWND hwnd;
};


void launchApp() {
// [RT-31061] otherwise UI can be left in back of other windows.
::AllowSetForegroundWindow(ASFW_ANY);
Expand Down Expand Up @@ -203,7 +279,7 @@ void launchApp() {
exec.arg(arg);
});

DWORD exitCode = static_cast<DWORD>(exec.execAndWaitForExit());
DWORD exitCode = RunExecutorWithMsgLoop::apply(exec);

exit(exitCode);
return;
Expand Down

8 comments on commit d3df3eb

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@lutkerd
Copy link
Contributor

@lutkerd lutkerd commented on d3df3eb Mar 4, 2024

Choose a reason for hiding this comment

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

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on d3df3eb Mar 4, 2024

Choose a reason for hiding this comment

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

@lutkerd the backport was successfully created on the branch backport-lutkerd-d3df3eb5 in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit d3df3eb5 from the openjdk/jdk repository.

The commit being backported was authored by Alexey Semenyuk on 5 Dec 2023 and was reviewed by Alexander Matveev.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-lutkerd-d3df3eb5:backport-lutkerd-d3df3eb5
$ git checkout backport-lutkerd-d3df3eb5
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-lutkerd-d3df3eb5

@lutkerd
Copy link
Contributor

@lutkerd lutkerd commented on d3df3eb Mar 4, 2024

Choose a reason for hiding this comment

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

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on d3df3eb Mar 4, 2024

Choose a reason for hiding this comment

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

@lutkerd Could not automatically backport d3df3eb5 to openjdk/jdk17u-dev due to conflicts in the following files:

  • src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk17u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk17u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b backport-lutkerd-d3df3eb5

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git d3df3eb5d7f5537ade917db7a36caba028f94111

# Backport the commit
$ git cherry-pick --no-commit d3df3eb5d7f5537ade917db7a36caba028f94111
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport d3df3eb5d7f5537ade917db7a36caba028f94111'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u-dev with the title Backport d3df3eb5d7f5537ade917db7a36caba028f94111.

Below you can find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit d3df3eb5 from the openjdk/jdk repository.

The commit being backported was authored by Alexey Semenyuk on 5 Dec 2023 and was reviewed by Alexander Matveev.

Thanks!

@TheRealMDoerr
Copy link
Contributor

Choose a reason for hiding this comment

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

Trying it again:
/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on d3df3eb May 27, 2024

Choose a reason for hiding this comment

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

@TheRealMDoerr Could not automatically backport d3df3eb5 to openjdk/jdk17u-dev due to conflicts in the following files:

  • src/jdk.jpackage/windows/native/applauncher/WinLauncher.cpp

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk17u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk17u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b backport-TheRealMDoerr-d3df3eb5

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git d3df3eb5d7f5537ade917db7a36caba028f94111

# Backport the commit
$ git cherry-pick --no-commit d3df3eb5d7f5537ade917db7a36caba028f94111
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport d3df3eb5d7f5537ade917db7a36caba028f94111'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk17u-dev with the title Backport d3df3eb5d7f5537ade917db7a36caba028f94111.

Below you can find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit d3df3eb5 from the openjdk/jdk repository.

The commit being backported was authored by Alexey Semenyuk on 5 Dec 2023 and was reviewed by Alexander Matveev.

Thanks!

@TheRealMDoerr
Copy link
Contributor

Choose a reason for hiding this comment

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

Strange. It's clean when I do it manually: openjdk/jdk17u-dev#2497

Please sign in to comment.