profesorfalken / jPowerShell

Simple Java API to interact with PowerShell console
Apache License 2.0
218 stars 84 forks source link

close() command hanging #1

Closed jadcsi closed 8 years ago

jadcsi commented 8 years ago

My code involves executing 2 Powershell commands in a session and then closing the powershell object. $PSVersionTable.PSVersion is:

Major Minor Build Revision


4 0 -1 -1

Problem is that the close() hangs

profesorfalken commented 8 years ago

Hello. Thank you for your feedback.

In order to fix it I will need more details: -Windows version -What kind of powershell commands are you trying to execute? -Does it work if you perform two executeSingleCommand instead?

Thanks

jadcsi commented 8 years ago

OS is Windows Server 2012 R2 Standard 64 bit and java version is 1.8

It wouldn't work if I ran it as 2 executeSingleCommand

1st command is: Import-Module to a psm1 file 2nd command is: Convert-DocxToHtml which is a method from the library imported

profesorfalken commented 8 years ago

Ok, and the problem is that the close() hangs? The Convert-DocxToHtml is correctly executed and it does its job? You have no logs from the library of type "timeout"?

Thank you

jadcsi commented 8 years ago

This is also happening when I execute your example:

   powerShell = PowerShell.openSession();
   PowerShellResponse response = powerShell.executeCommand("Get-Process");
   response = powerShell.executeCommand("Get-WmiObject Win32_BIOS");

Somehow maybe whenever we are executing more than one command.

profesorfalken commented 8 years ago

This is also happening when I execute your example:

Yes, but in my systems (Windows XP and Windows 7) it works and all the tests pass.

For that reason I would need more feedback of your problem.

I will try to reformulate the same questions I did in the last post: -Does it hangs in the close()? or in the executeCommand()? -The commands are executed correctly anyway before hanging? -Nothing in the logs?

Thanks

jadcsi commented 8 years ago

It hangs in the close() and the commands are executed correctly before hanging.

I am running it in debug mode in Eclipse and below are the lines executed for the close():

ln 141 ln 143 ln 151 ln 152 ln 163 ln 164 ln 165 ln 167 ln 171 ln 174 and it stays stuck here

profesorfalken commented 8 years ago

Cool, thank you. I will keep you updated.

profesorfalken commented 8 years ago

Apparently in your system the close() is not able to finish correctly all the threads used by the pool.

I have created a new branch to fix it. You can already download the snapshot version here: https://oss.sonatype.org/content/repositories/snapshots/com/profesorfalken/jPowerShell/1.3.1-SNAPSHOT/jPowerShell-1.3.1-20160226.195542-2.jar

Can you check If it works now and, if not, tell me what is the output?

Thank you

jadcsi commented 8 years ago

It is still hanging unfortunately with the new snapshot version. You can see its getting to the last curly brace of the java method and then hanging. There appears to be 3 threads tied to it in the Java Debugger as you can see from the Debugger screenshot:

hang

profesorfalken commented 8 years ago

And no logs? It is strange... I have added a lot of more code to locate&fix it.

Could you test it please?

https://oss.sonatype.org/content/repositories/snapshots/com/profesorfalken/jPowerShell/1.3.1-SNAPSHOT/jPowerShell-1.3.1-20160226.195542-3.jar

Thanks

jadcsi commented 8 years ago

No logs. I am getting a 404 for your new link

On Fri, Feb 26, 2016 at 12:33 PM, JGA notifications@github.com wrote:

And no logs? It is strange... I have added a lot of more code to locate&fix it.

Could you test it please?

https://oss.sonatype.org/content/repositories/snapshots/com/profesorfalken/jPowerShell/1.3.1-SNAPSHOT/jPowerShell-1.3.1-20160226.195542-3.jar

Thanks

— Reply to this email directly or view it on GitHub https://github.com/profesorfalken/jPowerShell/issues/1#issuecomment-189473039 .

profesorfalken commented 8 years ago

Good link: https://oss.sonatype.org/content/repositories/snapshots/com/profesorfalken/jPowerShell/1.3.1-SNAPSHOT/jPowerShell-1.3.1-20160226.203036-3.jar

jadcsi commented 8 years ago

Tested it and the only log message was this:

Feb 26, 2016 3:44:25 PM com.profesorfalken.jpowershell.PowerShell close INFO: Closing powerShell session...

On Fri, Feb 26, 2016 at 12:40 PM, JGA notifications@github.com wrote:

Good link:

https://oss.sonatype.org/content/repositories/snapshots/com/profesorfalken/jPowerShell/1.3.1-SNAPSHOT/jPowerShell-1.3.1-20160226.203036-3.jar

— Reply to this email directly or view it on GitHub https://github.com/profesorfalken/jPowerShell/issues/1#issuecomment-189475447 .

profesorfalken commented 8 years ago

I have cancelled the threads manually after use them. Can you try please?

https://oss.sonatype.org/content/repositories/snapshots/com/profesorfalken/jPowerShell/1.3.1-SNAPSHOT/jPowerShell-1.3.1-20160226.210511-4.jar

jadcsi commented 8 years ago

It is still hanging but below are the logs:

Feb 26, 2016 5:43:30 PM com.profesorfalken.jpowershell.PowerShell close INFO: Closing powerShell session... Feb 26, 2016 5:43:30 PM com.profesorfalken.jpowershell.PowerShell close INFO: ThreadPool going to shut down... Feb 26, 2016 5:43:30 PM com.profesorfalken.jpowershell.PowerShell close INFO: ThreadPool shutted down... Feb 26, 2016 5:43:30 PM com.profesorfalken.jpowershell.PowerShell close INFO: Its done

profesorfalken commented 8 years ago

Good news. After many tries I have reproduced it!

I will post here when fixed

profesorfalken commented 8 years ago

Done. The thread pool was initiliazed in the wrong place.

I have pushed the new 1.3.1 version with the fix but it will take several hours to be available on Maven Central.

Alternatively, you can already download the JAR file here: https://oss.sonatype.org/content/groups/staging/com/profesorfalken/jPowerShell/1.3.1/jPowerShell-1.3.1.jar

Please, can you confirm that it works for you so I can close the issue?

Thanks for your help.

jadcsi commented 8 years ago

Woohoo!! It works.

I even tested with my previous commands. I wish I could pay you back or get you a drink.

On Sat, Feb 27, 2016 at 8:54 AM, JGA notifications@github.com wrote:

Done. The thread pool was initiliazed in the wrong place.

I have pushed the new 1.3.1 version with the fix but it will take several hours to be available on Maven Central.

Alternatively, you can already download the JAR file here:

https://oss.sonatype.org/content/groups/staging/com/profesorfalken/jPowerShell/1.3.1/jPowerShell-1.3.1.jar

Please, can you confirm that it works and I close the issue?

Thanks for your help.

— Reply to this email directly or view it on GitHub https://github.com/profesorfalken/jPowerShell/issues/1#issuecomment-189681457 .

profesorfalken commented 8 years ago

Great news! The world is small, who knows if one day :-)

Thanks to you for helping me to locate the error.

I close this issue.