-
Notifications
You must be signed in to change notification settings - Fork 709
SOLR-17717 Use Powershell instead of WMIC to get cmdline on Windows #3291
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
Conversation
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.
Pull Request Overview
This PR addresses the issue with starting Solr on newer Windows 11 Home editions by introducing a fallback mechanism to fetch process command line information using PowerShell when WMIC is not available.
- Added a static flag (wmicAvailable) to check WMIC availability on Windows.
- Implemented a fallback in commandLine(...) to use PowerShell when WMIC is missing.
- Introduced helper methods: isWmicAvailable, commandLineViaWmic, and commandLineViaPowershell.
Files not reviewed (1)
- solr/CHANGES.txt: Language not supported
Comments suppressed due to low confidence (2)
solr/core/src/java/org/apache/solr/cli/SolrProcessManager.java:182
- In the commandLineViaWmic method, consider adding a process.waitFor() call after starting the process to ensure that WMIC has completed execution and produced all output before reading from its input stream.
Process process = new ProcessBuilder(
solr/core/src/java/org/apache/solr/cli/SolrProcessManager.java:182
- In isWmicAvailable, consider re-setting the thread's interrupt status when catching InterruptedException (e.g., by calling Thread.currentThread().interrupt()) to avoid unintentionally swallowing the interrupt flag.
Process process = new ProcessBuilder("wmic", "--version").start();
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.
LGTM.
One question about the approach... Could we JUST use powershell and not keep wmic support? Eventually it will be gone... Powershell has been around for quite a while now....
I'm not fluent enough in Windows world to know whether powershell.exe is available on all home, pro and server versions, so due to lack of integration tests on windows, it feels safer to handle it as a fallback for the existing approach. I wish Java implemented this for us in |
It is tempting to just defer this complexity to https://github.com/oshi/oshi as we discussed in the original feature issue. |
Powershell is available in Windows 10 and 11 for all variants. Servers have it, too. Windows 8 also has Powershell but its out of date. Windows 7 can install it. If anybody complains about Windows XP, I'm out of arguments. |
I thought you found a limitation that prevented oshi being viable? It looks like an active maintained library ;-). |
Please don't add new libraries (especially those with native code) just for a single function call. I'd remove the wmic support completely. It might also no longer be installed on freshly installed Windows 11 Pro or Servers. If you add libraries with native code, you need to whitelist them in later Java versions, because by default next LTS will disable native code via JNI and Panama. So it is now mandatory to add the command line option to enable it for Lucene Core (see recent upgrades to build scripts). Uwe |
Thanks for the review. I removed RMIC support. I have tested the PowerShell option on my UTM Win11 ARM VM and it works. However, my user is administrator, so I'd need to test with an unprivileged user as well. Feel free to give it a spin if you are on Win.. |
Did some more testing and a weakness of the solution is that the Powershell process is spawned once for every Java process running on the system, and each invocation takes some 3-5 seconds on the Win11 VM on my MacBook. Don't know if such slow invocation is representative for a real windows system, but it is an overhead. I have not done a comparison for the old wmic invocation. Manual command invocation in a PS terminal takes <1s. While manually invoking So I refactored the code to instead of calling PS once per PID, we do one full PID list on startup with
and stuffs it into a The OSHI library, using jna would probably be far more performant, but I agree that adding a 1Mb jar just for this is too much. |
Powershell is slow to start. Yes. Also on real machines. |
Simplify stream parsing Check for invocation success
# Conflicts: # solr/CHANGES.txt
Coming back to this. Lacking test suite on multiple windows versions makes such changes brittle. I hope the iterations we have done here and the reviews is enough to merge. And then hope the fix is not worse than what it replaces, except for perhaps added latency launching powershell. I'll go ahead and merge to main for now. |
…pache#3291) (cherry picked from commit 6315d3f)
…pache#3291) (cherry picked from commit 6315d3f)
…pache#3291) (cherry picked from commit 6315d3f)
https://issues.apache.org/jira/browse/SOLR-17717
The same information as we fetch with WMIC comamnd can be fetched with
powershell.exe
. It is slower, but more universal. Alternative would be native code via the OSHI library, but too heavy to include for just this one use.