From: "Ludovic Courtès" <ludo@gnu.org>
To: Christopher Baines <mail@cbaines.net>
Cc: Josselin Poiret <dev@jpoiret.xyz>,
Simon Tournier <zimon.toutoune@gmail.com>,
Mathieu Othacehe <othacehe@gnu.org>,
Tobias Geerinckx-Rice <me@tobias.gr>,
Ricardo Wurmus <rekado@elephly.net>,
67245@debbugs.gnu.org, Christopher Baines <guix@cbaines.net>
Subject: [bug#67245] [PATCH] store: Use a non-blocking socket for store connections.
Date: Sun, 26 Nov 2023 23:16:54 +0100 [thread overview]
Message-ID: <87fs0s17op.fsf@gnu.org> (raw)
In-Reply-To: <460cdfa67b473ea2f1593668b2d9d0fd159378d0.1700244314.git.mail@cbaines.net> (Christopher Baines's message of "Fri, 17 Nov 2023 18:05:14 +0000")
Hi Christopher,
Christopher Baines <mail@cbaines.net> skribis:
> For some applications, it's important to do this here rather than just making
> the socket non-blocking after the connection is established because there can
> be 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.
>
> * guix/store.scm (open-unix-domain-socket, open-inet-socket): Pass
> SOCK_NONBLOCK when calling socket.
>
> Change-Id: I8225762b78448bc1f7b698c8de5d736e13f577bf
I feel we should really discuss on Guix + Fibers since we’ve apparently
been going through the exact same set of issues. :-)
(The other thing that comes to mind is the resource pool!)
> +++ b/guix/store.scm
> @@ -460,7 +460,9 @@ (define (open-unix-domain-socket file)
> '&store-connection-error' upon error."
> (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)))
We cannot do this here because callers have to be prepared to deal with
non-blocking sockets, and that’s not the case in Guix itself.
In Cuirass, I have this:
--8<---------------cut here---------------start------------->8---
(define (non-blocking-port port)
"Make PORT non-blocking and return it."
(let ((flags (fcntl port F_GETFL)))
(when (zero? (logand O_NONBLOCK flags))
(fcntl port F_SETFL (logior O_NONBLOCK flags)))
port))
(define (ensure-non-blocking-store-connection store)
"Mark the file descriptor that backs STORE, a <store-connection>, as
O_NONBLOCK."
(match (store-connection-socket store)
((? file-port? port)
(non-blocking-port port))
(_ #f)))
(define-syntax-rule (with-store/non-blocking store exp ...)
"Like 'with-store', bind STORE to a connection to the store, but ensure that
said connection is non-blocking (O_NONBLOCK). Evaluate EXP... in that
context."
(with-store store
(ensure-non-blocking-store-connection store)
(let ()
exp ...)))
--8<---------------cut here---------------end--------------->8---
Then ‘with-store/non-blocking’ is used in fiberized context where I know
this is fine.
I think it’ll have to remain this way until Guix itself is fiberized or
something.
Does that make sense?
Ludo’.
next prev parent reply other threads:[~2023-11-26 22:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-17 18:05 [bug#67245] [PATCH] store: Use a non-blocking socket for store connections Christopher Baines
2023-11-26 22:16 ` Ludovic Courtès [this message]
2023-11-27 9:48 ` Christopher Baines
2023-11-30 21:11 ` Ludovic Courtès
2024-05-12 17:38 ` Christopher Baines
2024-05-11 16:53 ` [bug#67245] [PATCH v2] store: Add with-store/non-blocking Christopher Baines
2024-05-13 12:44 ` Ludovic Courtès
2024-05-13 19:32 ` bug#67245: " Christopher Baines
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fs0s17op.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=67245@debbugs.gnu.org \
--cc=dev@jpoiret.xyz \
--cc=guix@cbaines.net \
--cc=mail@cbaines.net \
--cc=me@tobias.gr \
--cc=othacehe@gnu.org \
--cc=rekado@elephly.net \
--cc=zimon.toutoune@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).