mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-24 05:18:07 -05:00
publish: Fix file descriptor leak.
A client closing the connection while reading from a /nar URL would leave an open file descriptor in the server. This patch fixes it. * guix/scripts/publish.scm (swallow-EPIPE): New macro. (http-write): Use it around 'write-file' call.
This commit is contained in:
parent
38e16b4907
commit
cf4e7083ed
1 changed files with 12 additions and 1 deletions
|
@ -256,6 +256,16 @@ (define (sans-content-length response)
|
|||
(response-headers response)
|
||||
eq?)))
|
||||
|
||||
(define-syntax-rule (swallow-EPIPE exp ...)
|
||||
"Swallow EPIPE errors raised by EXP..."
|
||||
(catch 'system-error
|
||||
(lambda ()
|
||||
exp ...)
|
||||
(lambda args
|
||||
(if (= EPIPE (system-error-errno args))
|
||||
(values)
|
||||
(apply throw args)))))
|
||||
|
||||
(define (http-write server client response body)
|
||||
"Write RESPONSE and BODY to CLIENT, possibly in a separate thread to avoid
|
||||
blocking."
|
||||
|
@ -274,7 +284,8 @@ (define (http-write server client response body)
|
|||
;; way to avoid building the whole nar in memory, which could
|
||||
;; quickly become a real problem. As a bonus, we even do
|
||||
;; sendfile(2) directly from the store files to the socket.
|
||||
(write-file (utf8->string body) port)
|
||||
(swallow-EPIPE
|
||||
(write-file (utf8->string body) port))
|
||||
(close-port port)
|
||||
(values)))))
|
||||
(_
|
||||
|
|
Loading…
Reference in a new issue