Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid logs full of java.io.IOException: Broken pipe [duplicate]

I am using Server-Sent events on one browser, and a spring boot application on the back end. When I shot down the client, I get the next exception:

14:35:09.458 [http-nio-8084-exec-25] ERROR o.a.c.c.C.[Tomcat].[localhost] - Exception Processing ErrorPage[errorCode=0, location=/error]
org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe

I understand this is the expected behavior; on the other hand, my application works fine, but I have awful logs full of those exceptions. I guess this is caused by Tomcat. Is there a way to catch these exceptions, or at least to prevent Tomcat from writing this exception stack trace to the log? I mean, without modifying Tomcat's code.

like image 460
Josi Avatar asked Feb 14 '26 15:02

Josi


1 Answers

To prevent this exception in logs you can try some changes in your code that performs push on client. Here is my example. I listen to api called and then it called I push socket to the client. I think you could understand the code:

 @GetMapping("/api/status/{groupId}/{groupstatusId}")
@ResponseStatus(HttpStatus.NO_CONTENT)
@ExceptionHandler(IOException.class)
public void listenToNewStatus(@PathVariable Long groupId, @PathVariable String groupstatusId, IOException e) {
    Group group = groupDTOService.findById(groupId);
    if (group != null) {
        if (StringUtils.containsIgnoreCase(ExceptionUtils.getRootCauseMessage(e), "Broken pipe")) {
            logger.info("broken pipe");
        } else {
            template.convertAndSend("/topic/callstatus/" + group.getUser().getId(), groupstatusId);
        }

    }

In this code to prevent broken pipe I add annotation @ExceptionHandler(IOException.class) and check if exception contains broken pipe then nothing else send message to client.

like image 95
Den B Avatar answered Feb 17 '26 05:02

Den B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!