Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Proper check of the existence of SSH tunnel attribute #1380

Merged
merged 2 commits into from
Sep 13, 2016

Conversation

objmagic
Copy link
Contributor

@objmagic objmagic commented Sep 13, 2016

The attribute tunnel is only added to the (Zookeeper) StateManager object when socket connection cannot be established and SSH is used instead.

When one is trying to shutdown the tracker, the (Zookeeper) state manager will be shutdown first. However, the original way of check if SSH tunnel has been establish is wrong. If one wants to check if the attribute tunnel exists in the StateManager object, he should use hasattr instead of if self.tunnel. The latter one assumes the attribute tunnel already exists in the object.

This PR should fix #1379

@objmagic objmagic added the bug label Sep 13, 2016
@objmagic objmagic self-assigned this Sep 13, 2016
@objmagic objmagic changed the title Proper check of the existence of SSH tunnel. Proper check of the existence of SSH tunnel attribute Sep 13, 2016
@@ -122,7 +122,7 @@ def establish_ssh_tunnel(self):
return localport

def terminate_ssh_tunnel(self):
if self.tunnel:
if hasattr(self, 'tunnel'):
Copy link
Contributor

Choose a reason for hiding this comment

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

What if it has the attribute but the value is None? Should we be doing this?

if hasattr(self, 'tunnel') and self.tunnel:

or is that redundant? Not sure if hasattr also covers self.tunnel not None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. Since self.tunnel is only set at this line and I tried a meaningless command to open a subprocess, the Popen still gave me back an object instead of a None, I think not checking None should be fine here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

import subprocess
p = subprocess.Popen(['ssh', 'twitter.com']) # should fail

p is still an object instead of a None.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but I think we can add this check just to be safe...

@billonahill
Copy link
Contributor

👍 once ci passes.

@kramasamy
Copy link
Contributor

@objmagic - it will be good to add the check as @billonahill suggested.

@mycFelix
Copy link
Contributor

It works! 👍

@objmagic objmagic merged commit c45ac3c into apache:master Sep 13, 2016
moomou pushed a commit to moomou/heron that referenced this pull request Sep 15, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to close heron-tracker in multi statemgrs config
4 participants