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

KARAF-7174: Implement a SSH channel resource cleaner whiteboard #1884

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jbonofre
Copy link
Member

No description provided.

@jbonofre jbonofre marked this pull request as draft November 12, 2024 15:53
@mattrpav
Copy link
Contributor

This is a great idea and useful feature. Esp for other commands that use connection pools, or other stateful resources.

One suggestion -- perhaps a rename for consistency?

CommandCloseListener?

@jbonofre
Copy link
Member Author

Yes,
Good point about the name. My only comment is that (potentially) it could be used for other services than commands. But let's start with shell commands :)

@mattrpav
Copy link
Contributor

Yes, Good point about the name. My only comment is that (potentially) it could be used for other services than commands. But let's start with shell commands :)

How do you see it working for other services? I think things like scr services should use deactivate(). I'm struggling to find a use case where another service would go 'out-of-scope' so to speak similar to how the shell command can timeout.

@jbonofre
Copy link
Member Author

@mattrpav I see a use case: a command use a service which starts a thread. The service has to be hook with ssh session to stop the thread when the session disconnects. So the service is not a shell command but it has to clean resources sync with ssh session.
SCR deactivate is a hook on SCR component lifecycle not the ssh session.

Collection<ServiceReference<ChannelResourceCleaner>> references = bundleContext.getServiceReferences(ChannelResourceCleaner.class, null);
for (ServiceReference<ChannelResourceCleaner> reference : references) {
ChannelResourceCleaner cleaner = bundleContext.getService(reference);
cleaner.close();
Copy link
Contributor

Choose a reason for hiding this comment

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

This appears to call .close() on every reference for every session that closes. Is that the correct association?

Wouldn't we want to close only the instance of the command associated with that session?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's right it's a bit agressive: if we have several ssh clients on the Karaf ssh server, we will close all references whatever is the client.
It's pretty hard to "link" the session with the command (or maybe we can use a session property to identify the correct session).

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good, a SSH sessionId stored in the command session state should do it.. then when the close loops, look for the matching one and close only that one.

Also, probably need a test with two sessions running.. first one aborts and second one stays active to confirm only the first one gets .close() called on it.

Copy link
Contributor

Choose a reason for hiding this comment

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

While we're at adding things to the Command/Action session.. this change is needed due to JDK removal of Security Manager: https://issues.apache.org/jira/browse/KARAF-7805

@mattrpav
Copy link
Contributor

mattrpav commented Nov 13, 2024

@mattrpav I see a use case: a command use a service which starts a thread. The service has to be hook with ssh session to stop the thread when the session disconnects. So the service is not a shell command but it has to clean resources sync with ssh session. SCR deactivate is a hook on SCR component lifecycle not the ssh session.

What about simply having Commands implement the JDK's built-in Closable interface and follow a convention vs marking the command with a domain-specific interface?

Seems like (commandInstance instanceof Closeable) would do the trick and we wouldn't need to create a new interface. Thoughts?

@jbonofre
Copy link
Member Author

@mattrpav that's a good idea to leverage Closeable. Let me do an experiment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants