guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#67245] [PATCH v2] store: Add with-store/non-blocking.


From: Ludovic Courtès
Subject: [bug#67245] [PATCH v2] store: Add with-store/non-blocking.
Date: Mon, 13 May 2024 14:44:18 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Hi,

Christopher Baines <mail@cbaines.net> skribis:

> For some applications, it's important to establish a non-blocking connection
> rather than just making the socket non-blocking after the connection is
> established. This is because there is I/O on the socket that will block during
> the handshake.
>
> I've noticed this blocking during the handshake causing issues in the build
> coordinator for example.
>
> This commit adds a new with-store variant to avoid changing the behaviour of
> with-store/open-connection to ensure that this change can't break anything
> that depends on the blocking nature of the socket.
>
> * guix/store.scm (open-unix-domain-socket, open-inet-socket): Take
>  #:non-blocking? and use SOCK_NONBLOCK when calling socket if appropriate.
> (connect-to-daemon, open-connection, call-with-store): Take #:non-blocking?
> and pass it on.
> (with-store/non-blocking): New syntax rule.
>
> Change-Id: I8225762b78448bc1f7b698c8de5d736e13f577bf

[...]

> +(define* (open-unix-domain-socket file #:key non-blocking?)
>    "Connect to the Unix-domain socket at FILE and return it.  Raise a
> -'&store-connection-error' upon error."
> +'&store-connection-error' upon error.  If NON-BLOCKING?, make the socket
> +non-blocking."
>    (let ((s (with-fluids ((%default-port-encoding #f))
>               ;; This trick allows use of the `scm_c_read' optimization.
> -             (socket PF_UNIX (logior SOCK_STREAM SOCK_CLOEXEC) 0)))
> +             (socket PF_UNIX
> +                     (logior SOCK_STREAM SOCK_CLOEXEC SOCK_NONBLOCK)
> +                     0)))

Make sure SOCK_NONBLOCK is added only when ‘non-blocking?’ is true.

> +(define-syntax-rule (with-store/non-blocking store exp ...)
> +  "Bind STORE to an non-blocking open connection to the store and evaluate
> +EXPs; automatically close the store when the dynamic extent of EXP is left."
> +  (call-with-store (lambda (store) exp ...) #:non-blocking? #t))

I think we’ll need an entry in ‘.dir-locals.el’ and one in (guix
read-print) for proper formatting.

OK for me with these changes!

Thanks,
Ludo’.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]