title: java.net.SocketTimeoutException: null
body: <p>I am working on a web application that accepts json data from third parties, processes that data and responds to them with processed json data.</p>
  
  <p>I am getting java.net.SocketTimeoutException: null on production server which I am unable to reproduce on my local machine. Below is the stack trace:</p>
  
  <pre><code>java.net.SocketTimeoutException: null
  at org.apache.tomcat.util.net.NioBlockingSelector.read(NioBlockingSelector.java:191)
  at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:246)
  at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:227)
  at org.apache.coyote.http11.InternalNioInputBuffer.readSocket(InternalNioInputBuffer.java:422)
  at org.apache.coyote.http11.InternalNioInputBuffer.fill(InternalNioInputBuffer.java:794)
  at org.apache.coyote.http11.InternalNioInputBuffer$SocketInputBuffer.doRead(InternalNioInputBuffer.java:819)
  at org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:124)
  at org.apache.coyote.http11.AbstractInputBuffer.doRead(AbstractInputBuffer.java:346)
  at org.apache.coyote.Request.doRead(Request.java:422)
  at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:290)
  at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:449)
  at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:315)
  at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:200)
  at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
  at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
  at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
  at java.io.InputStreamReader.read(InputStreamReader.java:184)
  at java.io.BufferedReader.fill(BufferedReader.java:154)
  at java.io.BufferedReader.read1(BufferedReader.java:205)
  at java.io.BufferedReader.read(BufferedReader.java:279)
  at java.io.Reader.read(Reader.java:140)
  </code></pre>
  
  <p>The piece of code that throws this exception (particularly 'while' condition):</p>
  
  <pre><code>public static String getPostData(HttpServletRequest request) throws 
  IOException {
      StringBuilder stringBuilder = new StringBuilder();
      BufferedReader bufferedReader = null;
      try {
          InputStream inputStream = request.getInputStream();
          if (inputStream != null) {
              bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
              char[] charBuffer = new char[128];
              int bytesRead = -1;
              while ((bytesRead = bufferedReader.read(charBuffer)) &gt; 0) {
                  stringBuilder.append(charBuffer, 0, bytesRead);
              }
          } else {
              stringBuilder.append("");
          }
      } finally {
          if (bufferedReader != null) {
              bufferedReader.close();
          }
      }
      return stringBuilder.toString();
  }
  </code></pre>
  
  <p>This application is deployed in 3 different AWS regions with the same server config and surprisingly only one of the regions throws this exception and that too only for a very few random requests.</p>
  
  <p>Any help is appreciated. Thanks in advance!</p>