diff options
author | Ludovic Courtès <ludo@gnu.org> | 2013-05-10 01:14:25 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2013-05-10 01:14:25 +0200 |
commit | dd9afe64b51aefb38e35e39b1f5ac8196cb70d21 (patch) | |
tree | 4c24b668d974f0eb105651971d25c7cdaad0293b | |
parent | a81bc5312ba26893c07f9aa432e4cc14e4ceefab (diff) | |
download | guix-dd9afe64b51aefb38e35e39b1f5ac8196cb70d21.tar.gz |
download: Fix premature socket close on TLS connections.
This would manifest when downloading a large file such as the Bazaar tarball, leading to an "Error in the pull function" GnuTLS exception. * guix/build/download.scm (add-weak-reference): New procedure. (tls-wrap): Add (add-weak-reference record port).
-rw-r--r-- | guix/build/download.scm | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/guix/build/download.scm b/guix/build/download.scm index 6c2e8235d0..53e6b2363c 100644 --- a/guix/build/download.scm +++ b/guix/build/download.scm @@ -101,6 +101,12 @@ abbreviation of URI showing the scheme, host, and basename of the file." (module-autoload! (current-module) '(gnutls) '(make-session connection-end/client)) +(define add-weak-reference + (let ((table (make-weak-key-hash-table))) + (lambda (from to) + "Hold a weak reference from FROM to TO." + (hashq-set! table from to)))) + (define (tls-wrap port) "Return PORT wrapped in a TLS connection." (define (log level str) @@ -117,7 +123,13 @@ abbreviation of URI showing the scheme, host, and basename of the file." ;;(set-log-procedure! log) (handshake session) - (session-record-port session))) + (let ((record (session-record-port session))) + ;; Since we use `fileno' above, the file descriptor behind PORT would be + ;; closed when PORT is GC'd. If we used `port->fdes', it would instead + ;; never be closed. So we use `fileno', but keep a weak reference to + ;; PORT, so the file descriptor gets closed when RECORD is GC'd. + (add-weak-reference record port) + record))) (define (open-connection-for-uri uri) "Return an open input/output port for a connection to URI. |