Menu

#18 Premature EOF when using forwarded channels

open
nobody
None
5
2004-06-30
2004-06-30
Dmitriy
No

A forwarding channel may report an EOF while there's
some still unconsumed data in local buffer. Thus, some
data may be lost during forwarding when channel gets
closed. This breaks certain protocols (although things
like http servers supporting persistent http
connections are not affected).

A simple fix could be applied to prevent a channel from
reporting EOF prematurely. The following changes work
for me, but it would be nice to fix that problem as
appropriate in the future since it is a quite serious
problem adding instability to protocols.

class: com.sshtools.j2ssh.connection.ChannelInputStream:
(DL PATCH marks changed lines, 0.2.7 source)

private void collectNextMessage()
throws MessageStoreEOFException,
InterruptedException, IOException {
// Collect the next message
startBlockingOperation();

try {
if (type != null) {
SshMsgChannelExtendedData msg = null;

// LD PATCH:
// while ((msg == null) && !isClosed()) {
while ( msg == null ) {

try {
log.debug("Waiting for extended
channel data");

// LD PATCH: abort only if
closed and no more messages.
boolean l_wasClosed = isClosed();
msg =
(SshMsgChannelExtendedData) messageStore.getMessage(filter,
interrupt);

// LD PATCH:
if ( msg == null && l_wasClosed ) {
log.debug ( "WAS CLOSED AND
NO MORE MESSAGES." );
break;
}

} catch
(MessageNotAvailableException ex) {
// Ignore the timeout but this
allows us to review the
// InputStreams state once in a
while
}
}

if (msg != null) {
msgdata = msg.getChannelData();
currentPos = 0;
} else {
throw new MessageStoreEOFException();
}
} else {
SshMsgChannelData msg = null;

// LD PATCH:
// while ((msg == null) && !isClosed()) {
while ( msg == null ) {
try {
log.debug("Waiting for channel
data");

// LD PATCH:
boolean l_wasClosed = isClosed();

msg = (SshMsgChannelData)
messageStore.getMessage(filter,
interrupt);

// LD PATCH
if ( msg == null && l_wasClosed ) {
log.debug ( "WAS CLOSED AND
NO MORE MESSAGES." );
break;
}

} catch
(MessageNotAvailableException ex1) {
// Ignore the timeout but this
allows us to review the
// InputStreams state once in a
while
}
}

if (msg != null) {
msgdata = msg.getChannelData();
currentPos = 0;
} else {
throw new MessageStoreEOFException();
}
}
} finally {
stopBlockingOperation();
}
}

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.