Ensure writer is closed while holding lock
Handler can inject its response content if lock is not held between write and close.
@@ -68,6 +68,7 @@ class ServletResponseController {
}
void fail(Throwable t) {
+ synchronized (monitor) {
try {
trySendError(t);
} catch (Throwable suppressed) {
@@ -76,6 +77,7 @@ class ServletResponseController {
out.close();
}
}
+ }
/**
* When this future completes there will be no more calls against the servlet output stream or servlet response.
@@ -88,7 +90,6 @@ class ServletResponseController {
ResponseHandler responseHandler() { return responseHandler; }
private void trySendError(Throwable t) {
- synchronized (monitor) {
if (!responseCommitted) {
responseCommitted = true;
servletResponse.setHeader(HttpHeaders.Names.EXPIRES, null);
@@ -118,7 +119,6 @@ class ServletResponseController {
log.log(Level.FINE, "Response already committed, can't change response code", exceptionWithStackTrace);
}
}
- }
private static int getStatusCode(Throwable t) {
if (t instanceof BindingNotFoundException) {
