Handling broken pipe exception in @ControllerAdvice does not work as well
<p>Good day. I know "broken pipe" is not an critical exception and it is mean client did not wait response from server. And i know there is many similar question but i can not find answer on s.o.</p>

<p>I want to keep my logs clear so i found <a href="http://mtyurt.net/2016/04/18/spring-how-to-handle-ioexception-broken-pipe/" rel="noreferrer">solution</a>.</p>

<p>And i tried to write it like:</p>

<pre><code>@ControllerAdvice
public class ControllerAdvisor {

    private static final Logger LOGGER = LogManager.getLogger();

    @ResponseBody
    @ExceptionHandler(IOException.class)
    @ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE)
    public Object brokenPipeHandle(IOException e, HttpServletRequest req) {

        if (StringUtils.containsIgnoreCase(ExceptionUtils.getRootCauseMessage(e), "Broken pipe"))
            return null;

        return new ErrorDto(e.getMessage());
    }
}
</code></pre>

<p>But Broken Pipe exception still happened and i have in logs:</p>

<pre><code>java.io.IOException: Broken pipe
    at sun.nio.ch.FileDispatcherImpl.write0(Native Method) ~[na:1.8.0_91]
    at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47) ~[na:1.8.0_91]
    at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93) ~[na:1.8.0_91]
    at sun.nio.ch.IOUtil.write(IOUtil.java:65) ~[na:1.8.0_91]
    at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471) ~[na:1.8.0_91]
    at org.apache.tomcat.util.net.NioChannel.write(NioChannel.java:134) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
    at org.apache.tomcat.util.net.NioBlockingSelector.write(NioBlockingSelector.java:101) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
    at org.apache.tomcat.util.net.NioSelectorPool.write(NioSelectorPool.java:157) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
    at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.doWrite(NioEndpoint.java:1241) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
    at org.apache.tomcat.util.net.SocketWrapperBase.flushBlocking(SocketWrapperBase.java:428) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
    at org.apache.tomcat.util.net.SocketWrapperBase.flush(SocketWrapperBase.java:418) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
    at org.apache.coyote.http11.Http11OutputBuffer.flushBuffer(Http11OutputBuffer.java:533) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
    at org.apache.coyote.http11.Http11OutputBuffer.flush(Http11OutputBuffer.java:250) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
    at org.apache.coyote.http11.Http11Processor.action(Http11Processor.java:691) ~[tomcat-embed-core-8.5.4.jar:8.5.4]
    at org.apache.coyote.Response.action(Response.java:167) [tomcat-embed-core-8.5.4.jar:8.5.4]
    at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:336) [tomcat-embed-core-8.5.4.jar:8.5.4]
    at org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:303) [tomcat-embed-core-8.5.4.jar:8.5.4]
    at org.apache.catalina.connector.Response.flushBuffer(Response.java:541) [tomcat-embed-core-8.5.4.jar:8.5.4]
    at org.apache.catalina.connector.ResponseFacade.flushBuffer(ResponseFacade.java:312) [tomcat-embed-core-8.5.4.jar:8.5.4]
    at javax.servlet.ServletResponseWrapper.flushBuffer(ServletResponseWrapper.java:176) [tomcat-embed-core-8.5.4.jar:8.5.4]
    at javax.servlet.ServletResponseWrapper.flushBuffer(ServletResponseWrapper.java:176) [tomcat-embed-core-8.5.4.jar:8.5.4]
    at org.springframework.security.web.util.OnCommittedResponseWrapper.flushBuffer(OnCommittedResponseWrapper.java:158) [spring-security-web-4.1.1.RELEASE.jar:4.1.1.RELEASE]
    at javax.servlet.ServletResponseWrapper.flushBuffer(ServletResponseWrapper.java:176) [tomcat-embed-core-8.5.4.jar:8.5.4]
    at org.springframework.security.web.util.OnCommittedResponseWrapper.flushBuffer(OnCommittedResponseWrapper.java:158) [spring-security-web-4.1.1.RELEASE.jar:4.1.1.RELEASE]
    at org.springframework.http.server.ServletServerHttpResponse.flush(ServletServerHttpResponse.java:96) [spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.web.socket.sockjs.transport.session.AbstractHttpSockJsSession.writeFrameInternal(AbstractHttpSockJsSession.java:365) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.writeFrame(AbstractSockJsSession.java:349) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.web.socket.sockjs.transport.session.StreamingSockJsSession.flushCache(StreamingSockJsSession.java:86) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.web.socket.sockjs.transport.session.AbstractHttpSockJsSession.sendMessageInternal(AbstractHttpSockJsSession.java:302) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession.sendMessage(AbstractSockJsSession.java:165) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator.tryFlushMessageBuffer(ConcurrentWebSocketSessionDecorator.java:132) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator.sendMessage(ConcurrentWebSocketSessionDecorator.java:104) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.web.socket.messaging.StompSubProtocolHandler.sendToClient(StompSubProtocolHandler.java:437) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.web.socket.messaging.StompSubProtocolHandler.handleMessageToClient(StompSubProtocolHandler.java:422) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.handleMessage(SubProtocolWebSocketHandler.java:338) [spring-websocket-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at org.springframework.messaging.support.ExecutorSubscribableChannel$SendTask.run(ExecutorSubscribableChannel.java:135) [spring-messaging-4.3.2.RELEASE.jar:4.3.2.RELEASE]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_91]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_91]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]
</code></pre>