Skip to content

Commit

Permalink
Fix of exception handler trying to write response to a disconnected c…
Browse files Browse the repository at this point in the history
…lient (#109)

Why:
On Conductor server side, an exception gets raised
`Failure in @ExceptionHandler com.netflix.conductor.rest.controllers.ApplicationExceptionMapper#handleAll(HttpServletRequest, Throwable)`.
Cause is attempting to write while the client aborted the connection
`org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe`

What:
Added a ClientAbortException handler.

Testing done: Local run. Not trivial to emulate the issue in a test.
Such a test may rely on timing out the client before server responded.

Signed-off-by: Iva Avramova <[email protected]>
  • Loading branch information
ivakoleva authored Apr 3, 2024
1 parent 05e7f72 commit 7e7b88b
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.HashMap;
import java.util.Map;

import org.apache.catalina.connector.ClientAbortException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
Expand All @@ -35,7 +36,6 @@
import jakarta.servlet.http.HttpServletRequest;

@RestControllerAdvice
@Order(ValidationExceptionMapper.ORDER + 1)
public class ApplicationExceptionMapper {

private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationExceptionMapper.class);
Expand All @@ -53,7 +53,16 @@ public class ApplicationExceptionMapper {
EXCEPTION_STATUS_MAP.put(NoResourceFoundException.class, HttpStatus.NOT_FOUND);
}

@ExceptionHandler(ClientAbortException.class)
@Order(ValidationExceptionMapper.ORDER + 1)
public void handleClientAborted(
HttpServletRequest request, ClientAbortException clientAbortException) {
logException(
request, clientAbortException); // socket closed, cannot return any error response
}

@ExceptionHandler(Throwable.class)
@Order(ValidationExceptionMapper.ORDER + 2)
public ResponseEntity<ErrorResponse> handleAll(HttpServletRequest request, Throwable th) {
logException(request, th);

Expand Down

0 comments on commit 7e7b88b

Please sign in to comment.