Subject: Re: bug#46967: Connection reuse for substitutes breaks with gzip

From: Ludovic Courtès <[email-masked]>
Date: Tue, 09 Mar 2021 14:13:08 +0100

Even simpler:

--8<---------------cut here---------------start------------->8---
$ ./pre-inst-env  guile ~/src/guix-debugging/http-pipelining-gzip.scm

;;; (port #<input-output: file 7fced4c20000>)

;;; (input #<input: file 7fced4c8ef50>)

;;; (drain "")

;;; (fetch 16397)

;;; (port #<input-output: file 7fced4c20000>)
Backtrace:
In ice-9/boot-9.scm:
  1736:10 11 (with-exception-handler _ _ #:unwind? _ #:unwind-for-type _)
In unknown file:
          10 (apply-smob/0 #<thunk 7fced7866520>)
In ice-9/boot-9.scm:
    718:2  9 (call-with-prompt _ _ #<procedure default-prompt-handler (k proc)>)
In ice-9/eval.scm:
    619:8  8 (_ #(#(#<directory (guile-user) 7fced7869c80>)))
In ice-9/boot-9.scm:
   2806:4  7 (save-module-excursion _)
  4351:12  6 (_)
In /home/ludo/src/guix-debugging/http-pipelining-gzip.scm:
     18:4  5 (_)
In guix/http-client.scm:
   116:21  4 (http-fetch _ #:port _ #:text? _ #:buffered? _ #:open-connection _ #:keep-alive? _ # _ #:headers _ # _)
In web/client.scm:
   526:24  3 (http-request _ #:body _ #:verify-certificate? _ #:port _ #:method _ #:version _ #:keep-alive? _ # _ # …)
In web/response.scm:
   198:31  2 (read-response #<input-output: string 7fced4c20000>)
In web/http.scm:
  1194:12  1 (read-response-line _)
    252:2  0 (parse-http-version _ _ _)

web/http.scm:252:2: In procedure parse-http-version:
Bad http-version header component: <!DOCTYPE

--8<---------------cut here---------------end--------------->8---

(use-modules (guix http-client)
             ((guix build download) #:select (open-connection-for-uri))
             (guix utils)
             ((guix serialization) #:select (dump-port*))
             (web uri)
             (web request)
             (web response)
             (srfi srfi-1))

(define %base-url
  "https://guix.gnu.org")

(define port
  (open-connection-for-uri (string->uri %base-url)))

(let loop ()
  (define-values (input size)
    (http-fetch (string->uri %base-url)
                #:port (pk 'port port)
                #:text? #f
                #:open-connection open-connection-for-uri ;/cached
                #:keep-alive? #t
                #:buffered? #f))

  (define-values (decompressed pids)
    (filtered-port '("/run/current-system/profile/bin/cat") (pk 'input input)))

  (dump-port* decompressed (%make-void-port "w")
              (pk 'fetch size))

  (unless (every (compose zero? cdr waitpid) pids)
    (error "decomp error"))

  (loop))