store: 'open-connection' no longer raises '&nar-error' for protocol errors.

* guix/store.scm (open-connection): Guard body against 'nar-error?' and
re-raise as '&nix-connection-error'.
* tests/store.scm ("connection handshake error"): New test.
This commit is contained in:
Ludovic Courtès 2016-12-08 14:03:33 +01:00
parent 0c69a17efd
commit 13d5e8dae5
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
2 changed files with 39 additions and 23 deletions

View File

@ -374,29 +374,36 @@ space on the file system so that the garbage collector can still operate,
should the disk become full. When CPU-AFFINITY is true, it must be an integer should the disk become full. When CPU-AFFINITY is true, it must be an integer
corresponding to an OS-level CPU number to which the daemon's worker process corresponding to an OS-level CPU number to which the daemon's worker process
for this connection will be pinned. Return a server object." for this connection will be pinned. Return a server object."
(let ((port (or port (open-unix-domain-socket file)))) (guard (c ((nar-error? c)
(write-int %worker-magic-1 port) ;; One of the 'write-' or 'read-' calls below failed, but this is
(let ((r (read-int port))) ;; really a connection error.
(and (eqv? r %worker-magic-2) (raise (condition
(let ((v (read-int port))) (&nix-connection-error (file (or port file))
(and (eqv? (protocol-major %protocol-version) (errno EPROTO))
(protocol-major v)) (&message (message "build daemon handshake failed"))))))
(begin (let ((port (or port (open-unix-domain-socket file))))
(write-int %protocol-version port) (write-int %worker-magic-1 port)
(when (>= (protocol-minor v) 14) (let ((r (read-int port)))
(write-int (if cpu-affinity 1 0) port) (and (eqv? r %worker-magic-2)
(when cpu-affinity (let ((v (read-int port)))
(write-int cpu-affinity port))) (and (eqv? (protocol-major %protocol-version)
(when (>= (protocol-minor v) 11) (protocol-major v))
(write-int (if reserve-space? 1 0) port)) (begin
(let ((conn (%make-nix-server port (write-int %protocol-version port)
(protocol-major v) (when (>= (protocol-minor v) 14)
(protocol-minor v) (write-int (if cpu-affinity 1 0) port)
(make-hash-table 100) (when cpu-affinity
(make-hash-table 100)))) (write-int cpu-affinity port)))
(let loop ((done? (process-stderr conn))) (when (>= (protocol-minor v) 11)
(or done? (process-stderr conn))) (write-int (if reserve-space? 1 0) port))
conn)))))))) (let ((conn (%make-nix-server port
(protocol-major v)
(protocol-minor v)
(make-hash-table 100)
(make-hash-table 100))))
(let loop ((done? (process-stderr conn)))
(or done? (process-stderr conn)))
conn)))))))))
(define (close-connection server) (define (close-connection server)
"Close the connection to SERVER." "Close the connection to SERVER."

View File

@ -48,6 +48,15 @@
(test-begin "store") (test-begin "store")
(test-equal "connection handshake error"
EPROTO
(let ((port (%make-void-port "rw")))
(guard (c ((nix-connection-error? c)
(and (eq? port (nix-connection-error-file c))
(nix-connection-error-code c))))
(open-connection #f #:port port)
'broken)))
(test-equal "store-path-hash-part" (test-equal "store-path-hash-part"
"283gqy39v3g9dxjy26rynl0zls82fmcg" "283gqy39v3g9dxjy26rynl0zls82fmcg"
(store-path-hash-part (store-path-hash-part