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

Added fix for thread error #341

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/winrm/shells/power_shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ def finalize(connection_opts, transport, shell_id)
end

def close_shell(connection_opts, transport, shell_id)
return false unless Thread.current.alive?
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, if Thread.current is not alive, how could this code be executing?

Copy link
Author

Choose a reason for hiding this comment

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

The thread is generally in asleep in my testing results. If it’s dead, I don’t think there’s much recourse that won’t potentially cause additional side effects. Maybe we rescue instead of returning.

Copy link
Member

Choose a reason for hiding this comment

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

It strikes me as super odd that the thread would be sleeping if the code is actually running. In your testing, are you examining the thread status of Thread.current or are you observing the thread's status from a different thread.

Thread.current.wakeup if Thread.current.status =~ /sleep/
msg = WinRM::WSMV::CloseShell.new(
connection_opts,
shell_id: shell_id,
shell_uri: WinRM::WSMV::Header::RESOURCE_URI_POWERSHELL
)
transport.send_request(msg.build)
rescue ThreadError => e
logger.debug("#{e.message}")
Copy link
Member

Choose a reason for hiding this comment

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

My concern is that this just masks an error that should probably be raised. The underlying transport is still unable to close the shell which could result in orphaned powershell processes on the remote.

end
end

Expand Down