unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Christopher Baines <mail@cbaines.net>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 67245-done@debbugs.gnu.org
Subject: bug#67245: [PATCH v2] store: Add with-store/non-blocking.
Date: Mon, 13 May 2024 20:32:16 +0100	[thread overview]
Message-ID: <878r0d33un.fsf@cbaines.net> (raw)
In-Reply-To: <87seylankt.fsf@gnu.org> ("Ludovic Courtès"'s message of "Mon, 13 May 2024 14:44:18 +0200")

[-- Attachment #1: Type: text/plain, Size: 2633 bytes --]

Ludovic Courtès <ludo@gnu.org> writes:

> 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.

Ah, yep, I've fixed this now.

>> +(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.

I've added an entry in to .dir-locals.el, but unless I've missed
something, (guix read-print) doesn't handle with-store so maybe we need
to add with-store and with-store/non-blocking.

> OK for me with these changes!

Great, I've pushed to 3db1a8341c815af3673c367518fbb193f5592864 and I can
follow up with the (guix read-print) changes and updating the guix
package later.

Thanks,

Chris

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 987 bytes --]

      reply	other threads:[~2024-05-13 19:33 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
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     ` Christopher Baines [this message]

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=878r0d33un.fsf@cbaines.net \
    --to=mail@cbaines.net \
    --cc=67245-done@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    /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).