#16 Race-condition forcefully disconnects session

open
nobody
None
5
2005-09-29
2005-09-29
No

I'm using jsch-0.1.21 from within Maven 2-beta-4 for
transport of artifacts from a remote repository with scp.

The file fetching is done in the Maven class ScpWagon
by creating an "exec" channel on a session upon which
the "scp -f /some/file" command is executed.

When ScpWagon noticies that the file has been completly
recieved (by counting bytes) it calls for
channel.disconnect() to terminate the channel.

This in turn sets the io attribute of the Channel
object to null.

Now, if the Session object has received
SSH_MSG_CHANNEL_EOF from the ssh server and managed to
fetch the Channel object before it was terminated (and
removed from the channel pool) by the terminate() call
from ScpWagon, it will simply crash on an NPE within
the eof_remote() method of the Channel. This will mark
the Session as disconnected, and the session thread dies.

The effect of this is that the _next_ time ScpWagon
tries to use Session, jsch reports (correctly) that the
session is down.

I guess that a fix for this should prevent multiple
threads to operate upon a Channel object at the same
time. More specifically, if a Channel object is fetched
from the pool, a thread should be able to assume that
no other thread changes any of the channels state.

A quick fix could also be to check for i io is null in
the Channels eof_remote() method.

Thanks,
Řrjan

Discussion

  • Logged In: YES
    user_id=113317

    One more note: simply checking for if io is null in
    eof_remote() did not do the trick...