From 8f92a6c32da01150400261515d3a4aa8a6ac4470 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Fri, 28 Jun 2024 09:04:48 +0200 Subject: Check for closed ports when writing chunks and give a hint to the user This makes it a bit more obvious what happened in cases like #1838, reported by Woodrow E Douglass. While at it, add some more test cases for this particular case, but also for retry-attempts, as this is also affected when retry is allowed for non-idempotent requests (which is pretty uncommon, but possible) --- http-client.scm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'http-client.scm') diff --git a/http-client.scm b/http-client.scm index 0dd9dff..58d045d 100644 --- a/http-client.scm +++ b/http-client.scm @@ -751,8 +751,16 @@ (open-input-file (cdr chunk)) ;; Should be a port otherwise (cdr chunk)))) + (when (port-closed? p) + (raise (http-client-error 'call-with-input-request* + (conc "At least one port for the multipart body has been already " + "consumed and closed. This may be due to a retry or a redirect. " + "Hint: use 'data:' or limit max-retry-attempts and " + "max-redirect-depth to zero and catch the resulting exception") + (list p) + 'port-already-consumed 'port p))) (handle-exceptions exn - (begin (close-input-port p) (raise exn)) + (begin (close-input-port p) (raise exn)) (sendfile p output-port)) (close-input-port p)) (display chunk output-port))) -- cgit v1.2.3