curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: curl: (23) Failed writing body (0 != 16383)

From: Ray Satiro via curl-users <curl-users_at_cool.haxx.se>
Date: Thu, 31 Dec 2020 18:55:58 -0500

On 12/31/2020 9:57 AM, Hongyi Zhao via curl-users wrote:
> $ curl -xhttp://127.0.0.1:8080 -fsSL
> https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64
> | grep -m1 -Po '\w+\.pub'
> 7fa2af80.pub
> 7fa2af80.pub
> curl: (23) Failed writing body (0 != 16383)
>
> I really want curl to quit gracefully once the first match happened.
> Why it gives the error shown above? How to achieve my purpose?


My guess is broken pipe because you passed -m1 so grep will exit after
the first matching line and then curl can't write the rest of the body.
curl may or may not exit with an error in that case. Since you used -S
[1] curl will output the error. message. However it's possible even if
you don't use -S with -s curl may still show you a failed body message
because this is an unusual case. I will bring that up for discussion in
the project issues.

Further, whether you actually get an error code from curl depends on
whether you're using shell pipefail. And the reason you see the same
match twice is because grep works matching by line but since you used
regex and -o it's showing each match from that first matching line.

To fix the regexp I think you could do '^.*?\K\w+\.pub' but that's not
going to suppress the error message. You could redirect stderr /dev/null
or write the output to a temporary file so that the full output is
written and an error doesn't occur and then grep from that. There are
probably better ways too, maybe others will have some ideas.


[1]: https://curl.se/docs/manpage.html#-S

-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2021-01-01