Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
servlet socket read timeout via reader

I am seeing this exception:

java.net.SocketTimeoutException: Timeout attempting to read data from the socket

Here's the code generating it:

    public static String extractBody(HttpServletRequest request) {
        StringBuffer sb = new StringBuffer();
        String line = null;
        try {
            //BufferedReader reader = request.getReader();
            BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
        } catch (Exception e) {
            logger.fatal("Failed to read from socket with content-length: {}", request.getHeader("Content-Length"));
            e.printStackTrace();
        }
        return sb.toString();
    }

When it happens, that content-length that's written is non-zero. It's like this

Failed to read from socket with content-length: 279645

What is causing this timeout? Is it that the socket was left unclosed by the client? Is there something else I am missing? Is there a different way I should be reading the body data from a servlet request? Most of the requests work fine, I only see this error sometimes but it may be a certain client version or platform or something.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The content-length header didn't match the actual content length and it was waiting for more data.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!