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(); 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) // For all messages, until another stream is ready (we send at least one message)
char[] message; do {
while ((message = reader.read()) != null) {
// Get message output bytes // Get message output bytes
out.write(message, 0, message.length); out.write(message, 0, message.length);
@@ -200,12 +207,7 @@ public abstract class GuacamoleTunnelServlet extends HttpServlet {
if (tunnel.hasQueuedReaderThreads()) if (tunnel.hasQueuedReaderThreads())
break; break;
} } while ((message = reader.read()) != null);
if (message == null) {
session.detachTunnel(tunnel);
throw new GuacamoleException("Disconnected.");
}
// End-of-instructions marker // End-of-instructions marker
out.write(';'); out.write(';');