* 8sync error in procedure select
@ 2021-05-03 15:57 Alexey Abramov
2021-05-04 18:58 ` Christopher Lemmer Webber
0 siblings, 1 reply; 2+ messages in thread
From: Alexey Abramov @ 2021-05-03 15:57 UTC (permalink / raw)
To: guile-user
[-- Attachment #1: Type: text/plain, Size: 1672 bytes --]
Hi,
I am trying to test an actor I wrote with 8sync. I created a probe actor
which sends messages to the main one. A problem I am having is that when
I want to send a *cleanup* to the main (server) actor from the probe, I
am getting the following backtrace:
--8<---------------cut here---------------start------------->8---
λ guile --debug -s tests/test.scm
Backtrace:
In ice-9/boot-9.scm:
1736:10 11 (with-exception-handler _ _ #:unwind? _ # _)
In unknown file:
10 (apply-smob/0 #<thunk 7fac09a7b9a0>)
In ice-9/boot-9.scm:
718:2 9 (call-with-prompt _ _ #<procedure default-prompt-handle…>)
In ice-9/eval.scm:
619:8 8 (_ #(#(#<directory (guile-user) 7fac096a0f00>)))
In ice-9/boot-9.scm:
2806:4 7 (save-module-excursion _)
4351:12 6 (_)
In 8sync/actors.scm:
812:6 5 (run-hive #<<hive> 7fac08bdd0c0> _ #:cleanup _ # _)
In ice-9/control.scm:
91:24 4 (call-with-escape-continuation _)
In 8sync/agenda.scm:
569:6 3 (run-agenda #<<agenda> queue: (() . #f) prompt-tag: ("…> …)
470:7 2 (update-agenda-from-select! #<<agenda> queue: (() . #f)…>)
In ice-9/boot-9.scm:
1731:15 1 (with-exception-handler #<procedure 7fac08bbd240 at ic…> …)
In unknown file:
0 (select (#<closed: file 7fac07ff6460>) () () #f #f)
ERROR: In procedure select:
In procedure select: Wrong type argument in position 1: #<closed: file 7fac07ff6460>
--8<---------------cut here---------------end--------------->8---
I have attached a simple snippet to reproduce the problem, and also a
naive patch I did. I am not sure if it is me doing the shutdown wrong, or
it's a bug.
--
Alexey
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-agenda-Honor-closed-ports.patch --]
[-- Type: text/x-patch, Size: 1143 bytes --]
From 020cdb7f7915876ff808b37430846a26dfab702b Mon Sep 17 00:00:00 2001
From: Alexey Abramov <levenson@mmer.org>
Date: Mon, 3 May 2021 16:53:04 +0200
Subject: [PATCH] agenda: Honor closed ports
* 8sync/agenda.scm (update-agenda-from-select!)[ports-to-select?]:
Cleanup ports which have been closed, before monitoring them with
select.
---
8sync/agenda.scm | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/8sync/agenda.scm b/8sync/agenda.scm
index e91487e..6b851a8 100644
--- a/8sync/agenda.scm
+++ b/8sync/agenda.scm
@@ -514,6 +514,13 @@ Also handles sleeping when all we have to do is wait on the schedule."
(not (= (hash-count (const #t)
(selector agenda))
0)))
+ (define (drop-closed-ports! table)
+ (for-each (lambda (port)
+ (when (port-closed? port)
+ (hash-remove! table port)))
+ (hash-keys table)))
+ (drop-closed-ports! (agenda-write-port-map agenda))
+ (drop-closed-ports! (agenda-read-port-map agenda))
(or (has-items? agenda-read-port-map)
(has-items? agenda-write-port-map)))
--
2.31.1
[-- Attachment #3: test.scm --]
[-- Type: application/octet-stream, Size: 1503 bytes --]
;;;
(use-modules (oop goops)
(ice-9 match)
(8sync actors)
(8sync ports)
(8sync repl))
(define (make-server-socket)
(let ((s (socket PF_INET SOCK_STREAM 0)))
(setsockopt s SOL_SOCKET SO_REUSEADDR 1)
(bind s AF_INET INADDR_LOOPBACK 4545)
(set-port-nonblocking! s)
s))
(define-actor <server> (<actor>)
((*init* (lambda (server message)
(listen (server-socket server) 5)
(while #t
(match (accept (server-socket server))
(#f
(close (server-socket server)))
((client . _)
(set-port-nonblocking! client)
(format client "S: hello~%")
(close client))))))
(*cleanup* (lambda (server message)
(false-if-exception
(close (server-socket server))))))
(server-socket
#:init-value #f
#:init-keyword #:server-socket
#:getter server-socket))
(define-actor <probe> (<actor>)
((*init* (lambda (probe message)
(let ((target (create-actor* probe <server> "server"
#:server-socket (make-server-socket))))
(slot-set! probe 'target target)
(<- target '*cleanup*)))))
(target
#:init-value #f
#:getter target))
(let* ((hive (make-hive))
;; (repl (bootstrap-actor hive <repl-manager>))
(probe (bootstrap-actor hive <probe>)))
(run-hive hive '()))
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: 8sync error in procedure select
2021-05-03 15:57 8sync error in procedure select Alexey Abramov
@ 2021-05-04 18:58 ` Christopher Lemmer Webber
0 siblings, 0 replies; 2+ messages in thread
From: Christopher Lemmer Webber @ 2021-05-04 18:58 UTC (permalink / raw)
To: Alexey Abramov; +Cc: guile-user
Hi! Hm... it might make sense to try switching to the "fibers" branch
of 8sync and see if that does better?
I guess I haven't worked on 8sync in some time, but really, the
intention was to switch it over to being on top of Fibers... Andy knew
more about building an event loop than I did ;P
Alexey Abramov writes:
> Hi,
>
> I am trying to test an actor I wrote with 8sync. I created a probe actor
> which sends messages to the main one. A problem I am having is that when
> I want to send a *cleanup* to the main (server) actor from the probe, I
> am getting the following backtrace:
>
> --8<---------------cut here---------------start------------->8---
> λ guile --debug -s tests/test.scm
> Backtrace:
> In ice-9/boot-9.scm:
> 1736:10 11 (with-exception-handler _ _ #:unwind? _ # _)
> In unknown file:
> 10 (apply-smob/0 #<thunk 7fac09a7b9a0>)
> In ice-9/boot-9.scm:
> 718:2 9 (call-with-prompt _ _ #<procedure default-prompt-handle…>)
> In ice-9/eval.scm:
> 619:8 8 (_ #(#(#<directory (guile-user) 7fac096a0f00>)))
> In ice-9/boot-9.scm:
> 2806:4 7 (save-module-excursion _)
> 4351:12 6 (_)
> In 8sync/actors.scm:
> 812:6 5 (run-hive #<<hive> 7fac08bdd0c0> _ #:cleanup _ # _)
> In ice-9/control.scm:
> 91:24 4 (call-with-escape-continuation _)
> In 8sync/agenda.scm:
> 569:6 3 (run-agenda #<<agenda> queue: (() . #f) prompt-tag: ("…> …)
> 470:7 2 (update-agenda-from-select! #<<agenda> queue: (() . #f)…>)
> In ice-9/boot-9.scm:
> 1731:15 1 (with-exception-handler #<procedure 7fac08bbd240 at ic…> …)
> In unknown file:
> 0 (select (#<closed: file 7fac07ff6460>) () () #f #f)
>
> ERROR: In procedure select:
> In procedure select: Wrong type argument in position 1: #<closed: file 7fac07ff6460>
> --8<---------------cut here---------------end--------------->8---
>
> I have attached a simple snippet to reproduce the problem, and also a
> naive patch I did. I am not sure if it is me doing the shutdown wrong, or
> it's a bug.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-05-04 18:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-03 15:57 8sync error in procedure select Alexey Abramov
2021-05-04 18:58 ` Christopher Lemmer Webber
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).