Constant timeout from client in stage #QV8 [http-server] [Java]

I’m stuck on stage 8.

I’ve tried to debug my code in many ways, but no matter what I do I can see that issue must be on the client side.

Here are my logs with the request which I should process:

[stage-8] Sending request: (Messages with >>> prefix are part of this log)
[stage-8] >>> POST /files/mango_orange_strawberry_grape HTTP/1.1
[stage-8] >>> Host: localhost:4221
[stage-8] >>> User-Agent: Go-http-client/1.1
[stage-8] >>> Content-Length: 59
[stage-8] >>> Accept-Encoding: gzip
[stage-8] >>> 
[stage-8] >>> banana banana grape pear orange strawberry pineapple banana

...
[your_program] Debug line1 Accept-Encoding: gzip
[your_program] Debug line1 
[stage-8] Failed to connect to server, err: 'Post "http://localhost:4221/files/mango_orange_strawberry_grape": context deadline exceeded (Client.Timeout exceeded while awaiting headers)'
[stage-8] Test failed

So what is exactly happening? I can read headers and one line after them (“Debug line1 …”) and then request processing freezes (even in my test in VSC stops for 2-3 seconds, so it’s clear it’s waiting for input). I tried below ways to debug:

  • while loop to read headers and stop when empty line arrives, then start new while loop to read body
  • while loop that ignores line content and simply reads 10 lines no matter what (it should read 4 lines of headers, one empty line, one body line and only then possibly crash)
  • while look that reads headers, stops when empty line arrives, then prints some random stuff, then does some calculations and prints it and only then starts second while loop to read body
  • same like previous, but it doesn’t have second while loop and instead tries to read just one more line (which sould be body)
    In each case I output each line to console to see what was read at the time when it arrives and every single time timeout error comes just before body line should be read. I spent couple of hours on this and I give up… Any help is appreviated.

@chalvagit can you post a link to your code? (preferably on GitHub so it’s easy to read). Hard to tell what’s going on without that.

I’d also recommend logging out the raw bytes you’re receiving, that might help.

We’re pushing some improvements to logs this week so you’ll see the exact bytes that are sent. Will notify here once that’s out!

I’ve found out the issue - somehow readLine() was getting so long that it was timing out the request, but from time to time it was still posting the message to logs, but when it was too late. So I started reading char by char with read() and it was working fine, so I realised that body line probably never ends… I have no idea why would that be, but the only way to actually go through with this stage is to read the exact amount of chars from body as the Content-lenght header says and then sent response, otherwise you are stuck and you don’t even know why…

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.

Note: I’ve updated the title of this post to include the stage ID (#QV8). You can learn about the stages rename here: Upcoming change: Stages overhaul.