J2SSH 0.2.7 can fail on startup with a ConcurrentModificationException in processChannelData called by the AsyncService thread. This seems to be a timing problem in com.sshtools.j2ssh.connection.Channel when an eventListener as added at the same time as processChannelData is handling a message. This occurs in an environment where J2SSH is running on a multi-processor system (4 CPUs) opening a session to a server on the local high-speed LAN. An exception occurs about 50% of the time when opening an SSH session.
There is synchronization code in Channel but this is not used in addEventListener. I modified addEventListener to be synchronized on the state object and that seems to fix the problem. The updated addEventListener code in Channel looks like this:
public void addEventListener(ChannelEventListener eventListener) {
synchronized (state) { eventListeners.add(eventListener); }
}
The log information and stack trace follows:
Mar 29, 2007 1:14:22 PM com.sshtools.j2ssh.transport.Service start
INFO: ssh-connection has been requested
Mar 29, 2007 1:14:22 PM com.sshtools.j2ssh.transport.AsyncService onStart
INFO: Starting ssh-connection service thread
Mar 29, 2007 1:14:22 PM com.sshtools.j2ssh.connection.ConnectionProtocol openChannel
INFO: Channel 0 is open [session]
Mar 29, 2007 1:14:22 PM com.sshtools.j2ssh.session.SessionChannelClient requestPseudoTerminal
INFO: Requesting pseudo terminal
Mar 29, 2007 1:14:22 PM com.sshtools.j2ssh.transport.AsyncService run
SEVERE: Service message loop failed!
java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
at java.util.AbstractList$Itr.next(Unknown Source)
at com.sshtools.j2ssh.connection.Channel.processChannelData(Unknown Source)
at com.sshtools.j2ssh.connection.ConnectionProtocol.onMsgChannelData(Unknown Source)
at com.sshtools.j2ssh.connection.ConnectionProtocol.onMessageReceived(Unknown Source)
at com.sshtools.j2ssh.transport.AsyncService.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)