Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does reading from file descriptor 3 hangs with bash and network redirection?

I am using bash and network redirection to send HTTP requests.

Here is the request I am sending:

exec 3<> $initial_url
path="/webhdfs/v1$hdfs_target?user.name=hdfs&op=OPEN"
printf "GET $path HTTP/1.1\r\nHost: $url:$port\r\nAccept: */*\r\n\r\n" >&3
echo toto
cat <&3
echo titi
exec 3<&

I am recieving the response correctly. However, the cat just hangs indefinitely. Here is an execution output (killed with ctrl+c):

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$ time bash toto.sh
toto
HTTP/1.1 307 TEMPORARY_REDIRECT
Cache-Control: no-cache
Expires: Thu, 20 Jul 2023 12:29:41 GMT
Date: Thu, 20 Jul 2023 12:29:41 GMT
Pragma: no-cache
Expires: Thu, 20 Jul 2023 12:29:41 GMT
Date: Thu, 20 Jul 2023 12:29:41 GMT
Pragma: no-cache
X-FRAME-OPTIONS: SAMEORIGIN
Set-Cookie: hadoop.auth="redacted_for_SO"; Path=/; HttpOnly
Location: redacted_for_SO
Content-Type: application/octet-stream
Content-Length: 0



real    0m19.042s
user    0m0.124s
sys     0m0.733s

There is everything I need in this output, but as said, the cat never ends.

  • Why is the cat hanging ? What is it waiting for ?
  • How to prevent it from hanging when the data has been recieved ?

>Solution :

You should add a Connection: close header to your request so that the server will close the connection once it’s finished sending the response. See also here: https://serverfault.com/questions/790197/what-does-connection-close-mean-when-used-in-the-response-message

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading