Fix race condition where tunnel is detached before client has chance to retrieve error message in header via second request.

This commit is contained in:
Michael Jumper
2011-07-04 14:24:40 -07:00
parent 423d1a6268
commit 88b186a856

View File

@@ -187,9 +187,16 @@ public abstract class GuacamoleTunnelServlet extends HttpServlet {
Writer out = response.getWriter();
// Detach tunnel and throw error if EOF (and we haven't sent any
// data yet.
char[] message = reader.read();
if (message == null) {
session.detachTunnel(tunnel);
throw new GuacamoleException("Disconnected.");
}
// For all messages, until another stream is ready (we send at least one message)
char[] message;
while ((message = reader.read()) != null) {
do {
// Get message output bytes
out.write(message, 0, message.length);
@@ -200,12 +207,7 @@ public abstract class GuacamoleTunnelServlet extends HttpServlet {
if (tunnel.hasQueuedReaderThreads())
break;
}
if (message == null) {
session.detachTunnel(tunnel);
throw new GuacamoleException("Disconnected.");
}
} while ((message = reader.read()) != null);
// End-of-instructions marker
out.write(';');