title: Postgres 11, receiving broken pipe, if stays inactive
body: <p>Spring application is logging broken pipe occasionally. To deal with stale connections issue, application is already using -</p>
  
  <blockquote>
    <p><em>testWhileIdle=true</em> and <em>validationQuery=SELECT 1</em> </p>
  </blockquote>
  
  <p>Stack trace -</p>
  
  <pre><code>    Caused by: org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
              at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:333)
              at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
              at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
              at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:155)
              at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:118)
              at sun.reflect.GeneratedMethodAccessor89.invoke(Unknown Source)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:498)
              at org.apache.tomcat.jdbc.pool.StatementFacade$StatementProxy.invoke(StatementFacade.java:114)
              at com.sun.proxy.$Proxy137.executeQuery(Unknown Source)
              at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70)
              ... 133 more
      Caused by: java.net.SocketException: Connection reset
              at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:115)
              at java.net.SocketOutputStream.write(SocketOutputStream.java:155)
              at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
              at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
              at org.postgresql.core.PGStream.flush(PGStream.java:514)
              at org.postgresql.core.v3.QueryExecutorImpl.sendSync(QueryExecutorImpl.java:1363)
              at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:304)
              ... 143 more
       Caused by java.net.SocketException: Broken pipe (Write failed)
  </code></pre>
  
  <p>A vague feeling, if application stays inactive for while, then it might be giving problem connecting to backend or vice-versa. But since can not reproduce this issue locally, it is hard to point.</p>