* using shepherd's (shepherd service repl) in guix system
@ 2023-12-21 14:46 Justin Veilleux
2024-01-09 22:36 ` Ludovic Courtès
0 siblings, 1 reply; 3+ messages in thread
From: Justin Veilleux @ 2023-12-21 14:46 UTC (permalink / raw)
To: guix-devel
Hi. I thought it would be interesting to have a shepherd service run a
repl like in
https://www.gnu.org/software/shepherd/manual/html_node/REPL-Service.html.
Since there is no shepherd repl service in a (gnu services *) module, I
created a shepherd-service-type and shepherd-service (I copied the code
from `(shepherd service repl)`)
The `reconfigure` runs and after fiddling with permission bits and
connecting to the socket through emacs and geiser (like in the manual),
I am able to execute expressions such as `(+ 2 2)` and `(display
"test\n")` and everything works as expected.
However, when I try to evaluate `lookup-service` (without calling it),
the repl gets stuck in an infinite loop of
> scheme@(shepherd-user) [1]> While reading expression:
> Attempt to suspend fiber within continuation barrier
This is annoying, since inspecting the state of shepherd is my main use
case for the REPL service. Has anyone encountered this problem?
The `shepherd-repl-service-type`:
> (define shepherd-repl-service-type
> (service-type
> (name 'shepherd-repl)
> (description "Run a shepherd repl")
> (default-value "/var/run/shepherd/repl")
> (extensions
> (list
> (service-extension
> shepherd-root-service-type
> (lambda (socket-file)
> (list
> (shepherd-service
> (documentation "Run the shepherd repl")
> (provision '(repl))
> (requirement '())
> (start #~(lambda args
> (format #t "socket file: ~s\n" #$socket-file)
> (with-exception-handler
> (lambda (exn)
> #f)
> (lambda ()
> (delete-file #$socket-file))
> #:unwind? #t)
> (let ((socket (open-server-socket #$socket-file)))
> ((@@ (shepherd service repl) spawn-repl-service) socket)
> socket)))
> (stop #~(lambda (socket)
> (close-port socket)
> #f))
> (modules (cons*
> '(shepherd service repl)
> '(shepherd comm)
> %default-modules))))))))))
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: using shepherd's (shepherd service repl) in guix system
2023-12-21 14:46 using shepherd's (shepherd service repl) in guix system Justin Veilleux
@ 2024-01-09 22:36 ` Ludovic Courtès
2024-01-11 9:26 ` Andy Wingo
0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2024-01-09 22:36 UTC (permalink / raw)
To: Justin Veilleux; +Cc: guix-devel
Hello,
Justin Veilleux <terramorpha@cock.li> skribis:
> Hi. I thought it would be interesting to have a shepherd service run a
> repl like in
> https://www.gnu.org/software/shepherd/manual/html_node/REPL-Service.html.
> Since there is no shepherd repl service in a (gnu services *) module, I
> created a shepherd-service-type and shepherd-service (I copied the code
> from `(shepherd service repl)`)
Another option is to turn it on only when you need it, along these
lines:
herd eval root '(begin (use-modules (shepherd service repl))
(register-services (list (repl-service))))'
herd start repl
(Granted, it’s not as convenient.)
> The `reconfigure` runs and after fiddling with permission bits and
> connecting to the socket through emacs and geiser (like in the manual),
> I am able to execute expressions such as `(+ 2 2)` and `(display
> "test\n")` and everything works as expected.
>
> However, when I try to evaluate `lookup-service` (without calling it),
> the repl gets stuck in an infinite loop of
>
>> scheme@(shepherd-user) [1]> While reading expression:
>> Attempt to suspend fiber within continuation barrier
Yes:
--8<---------------cut here---------------start------------->8---
scheme@(shepherd-user)> (+ 2 3)
$6 = 5
scheme@(shepherd-user)> (lookup-service 'repl)
;;; socket:56:1: warning: possibly unbound variable `lookup-service'
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Unbound variable: lookup-service
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme@(shepherd-user) [1]> While reading expression:
Attempt to suspend fiber within continuation barrier
scheme@(shepherd-user) [1]> While reading expression:
Attempt to suspend fiber within continuation barrier
--8<---------------cut here---------------end--------------->8---
The problem here is that the exception is raised C code (in
libguile/modules.c, then indirectly calling ‘scm_error’), which makes it
a “continuation barrier” (meaning that it prevents Fibers from switching
contexts among fibers in the shepherd process, hence the error above.)
The same goes for many exceptions launched from libguile primitives (for
instance division by zero), but it’s fine if we take a C-free path:
--8<---------------cut here---------------start------------->8---
scheme@(shepherd-user)> (raise-exception 123)
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Throw to key `%exception' with args `(123)'.
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme@(shepherd-user) [1]> ,bt
In ice-9/boot-9.scm:
1685:16 0 (raise-exception _ #:continuable? _)
scheme@(shepherd-user) [1]> ,q
scheme@(shepherd-user)> (+ 1 2)
$31 = 3
--8<---------------cut here---------------end--------------->8---
And of course it’s all good when there are no exceptions:
--8<---------------cut here---------------start------------->8---
scheme@(shepherd-user)> ,use(shepherd service)
scheme@(shepherd-user)> (lookup-service 'repl)
$12 = #<<service> 7fbd052fabd0>
scheme@(shepherd-user)> (lookup-service 'root)
$13 = #<<service> 7fbd056fd1c0>
scheme@(shepherd-user)> (service-status $12)
$14 = running
scheme@(shepherd-user)> (service-status-changes $12)
$15 = ((running . 1704838523) (starting . 1704838523))
--8<---------------cut here---------------end--------------->8---
This is undoubtedly a shortcoming for the REPL.
The solution here would be to arrange for Guile primitives to raise
exceptions through a different path somehow. Not sure how.
Thanks,
Ludo’.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: using shepherd's (shepherd service repl) in guix system
2024-01-09 22:36 ` Ludovic Courtès
@ 2024-01-11 9:26 ` Andy Wingo
0 siblings, 0 replies; 3+ messages in thread
From: Andy Wingo @ 2024-01-11 9:26 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: Justin Veilleux, guix-devel
On Tue 09 Jan 2024 23:36, Ludovic Courtès <ludo@gnu.org> writes:
> scheme@(shepherd-user)> (+ 2 3)
> $6 = 5
> scheme@(shepherd-user)> (lookup-service 'repl)
> ;;; socket:56:1: warning: possibly unbound variable `lookup-service'
> ice-9/boot-9.scm:1685:16: In procedure raise-exception:
> Unbound variable: lookup-service
>
> Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
> scheme@(shepherd-user) [1]> While reading expression:
> Attempt to suspend fiber within continuation barrier
> scheme@(shepherd-user) [1]> While reading expression:
> Attempt to suspend fiber within continuation barrier
>
>
> The problem here is that the exception is raised C code (in
> libguile/modules.c, then indirectly calling ‘scm_error’), which makes it
> a “continuation barrier” (meaning that it prevents Fibers from switching
> contexts among fibers in the shepherd process, hence the error above.)
Interesting. I guess the short-term fix is to only enter the debugger
if suspendable-continuation? is true for the fibers prompt, and
otherwise just print a backtrace.
Andy
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-01-11 9:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-21 14:46 using shepherd's (shepherd service repl) in guix system Justin Veilleux
2024-01-09 22:36 ` Ludovic Courtès
2024-01-11 9:26 ` Andy Wingo
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.