[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
05/05: publish: Fix file descriptor leak.
From: |
Ludovic Courtès |
Subject: |
05/05: publish: Fix file descriptor leak. |
Date: |
Tue, 06 Oct 2015 21:51:15 +0000 |
civodul pushed a commit to branch master
in repository guix.
commit cf4e7083ed1bc89b9585f0121ebb6c56c291d0ad
Author: Ludovic Courtès <address@hidden>
Date: Tue Oct 6 23:45:38 2015 +0200
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.
---
guix/scripts/publish.scm | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm
index e352090..fb7b421 100644
--- a/guix/scripts/publish.scm
+++ b/guix/scripts/publish.scm
@@ -256,6 +256,16 @@ example: \"/foo/bar\" yields '(\"foo\" \"bar\")."
(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 @@ blocking."
;; 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)))))
(_