Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 0.4.0
    • Fix Version/s: 0.5.0
    • Labels:
      None

      Description

      Is there a way for a org.apache.sshd.server.Command to detect that a user has
      disconnected? I'd like to shutdown my command shell when this happens. For example, when a user disconnects their SSH client (e.g open ssh "~.").

        Activity

        Hide
        Russ Tennant added a comment -

        I haven't seen any bad behavior. I was using open ssh to test this. I used the escape character, , and the period character, ., with open ssh to disconnect, ".".

        Show
        Russ Tennant added a comment - I haven't seen any bad behavior. I was using open ssh to test this. I used the escape character, , and the period character, ., with open ssh to disconnect, " .".
        Hide
        Guillaume Nodet added a comment -

        Committing to https://svn.apache.org/repos/asf/mina/sshd/trunk ...
        M sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java
        M sshd-core/src/test/java/org/apache/sshd/ClientTest.java
        Committed r1027569

        Show
        Guillaume Nodet added a comment - Committing to https://svn.apache.org/repos/asf/mina/sshd/trunk ... M sshd-core/src/main/java/org/apache/sshd/server/session/ServerSession.java M sshd-core/src/test/java/org/apache/sshd/ClientTest.java Committed r1027569
        Hide
        Guillaume Nodet added a comment -

        I've added a junit test in ClientTest to try reproducing the behavior but everything seems to work fine.
        Which client to do use ? I wonder if the client is not in a state to answer the channel close methods, maybe the server will wait forever.

        Show
        Guillaume Nodet added a comment - I've added a junit test in ClientTest to try reproducing the behavior but everything seems to work fine. Which client to do use ? I wonder if the client is not in a state to answer the channel close methods, maybe the server will wait forever.
        Hide
        Guillaume Nodet added a comment -

        Have you seen any bad behavior with the above patch ?

        Show
        Guillaume Nodet added a comment - Have you seen any bad behavior with the above patch ?
        Hide
        Russ Tennant added a comment - - edited

        No, it doesn't for me. I thought that was purposeful although I didn't read the spec to verify.

        In ServerSession.java, close(false) is called which doesn't cause Command.destroy() to be called. If I changed that to close(true), then destroy is called.

        protected void handleMessage(Buffer buffer) throws Exception {
        118 SshConstants.Message cmd = buffer.getCommand();
        119 log.debug("Received packet {}", cmd);
        120 switch (cmd) {
        121 case SSH_MSG_DISCONNECT: {
        122 int code = buffer.getInt();
        123 String msg = buffer.getString();
        124 log.info("Received SSH_MSG_DISCONNECT (reason={}, msg={})", code, msg);
        125 close(false);
        126 break;
        127 }

        Show
        Russ Tennant added a comment - - edited No, it doesn't for me. I thought that was purposeful although I didn't read the spec to verify. In ServerSession.java, close(false) is called which doesn't cause Command.destroy() to be called. If I changed that to close(true), then destroy is called. protected void handleMessage(Buffer buffer) throws Exception { 118 SshConstants.Message cmd = buffer.getCommand(); 119 log.debug("Received packet {}", cmd); 120 switch (cmd) { 121 case SSH_MSG_DISCONNECT: { 122 int code = buffer.getInt(); 123 String msg = buffer.getString(); 124 log.info("Received SSH_MSG_DISCONNECT (reason={}, msg={})", code, msg); 125 close(false); 126 break; 127 }
        Hide
        Guillaume Nodet added a comment -

        When the server receives the SSH_MSG_DISCONNECT on a session, it closes down all channels, and the currently executed command should have its destroy() method called.
        Isn't that the case for you?

        Show
        Guillaume Nodet added a comment - When the server receives the SSH_MSG_DISCONNECT on a session, it closes down all channels, and the currently executed command should have its destroy() method called. Isn't that the case for you?

          People

          • Assignee:
            Guillaume Nodet
            Reporter:
            Russ Tennant
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development