Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ‘epoll instance is dead #61’ #62

Merged
merged 2 commits into from Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion fibers/epoll.scm
@@ -1,6 +1,7 @@
;; epoll

;;;; Copyright (C) 2016 Andy Wingo <wingo@pobox.com>
;;;; Copyright (C) 2022 Maxime Devos <maximedevos@telenet.be>
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -135,7 +136,12 @@ epoll wait (if appropriate)."
('waiting
(primitive-epoll-wake (fileno (epoll-wake-write-pipe epoll))))
('not-waiting #t)
('dead (error "epoll instance is dead"))))
;; This can happen if a fiber was waiting on a condition and
;; run-fibers completes before the fiber completes and afterwards
;; the condition is signalled. In that case, we don't have to
;; resurrect the fiber or something, we can just do nothing.
;; (Bug report: https://github.com/wingo/fibers/issues/61)
('dead #t)))

(define (epoll-default-folder fd events seed)
(acons fd events seed))
Expand Down
20 changes: 20 additions & 0 deletions tests/conditions.scm
@@ -1,6 +1,7 @@
;; Fibers: cooperative, event-driven user-space threads.

;;;; Copyright (C) 2016 Free Software Foundation, Inc.
;;;; Copyright (C) 2022 Maxime Devos <maximedevos@telenet.be>
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
Expand All @@ -21,6 +22,7 @@
#:use-module (fibers)
#:use-module (fibers conditions)
#:use-module (fibers operations)
#:use-module (fibers scheduler)
#:use-module (fibers timers))

(define failed? #f)
Expand Down Expand Up @@ -78,4 +80,22 @@
(wait cv)
#t))

;; Make a condition, wait for it inside a fiber, let the fiber abruptly
;; terminate and signal the condition afterwards. This tests for the bug
;; noticed at <https://github.com/wingo/fibers/issues/61>.
(assert-equal #t
(let ((cv (make-condition)))
(run-fibers
(lambda ()
(spawn-fiber (lambda () (wait cv)))
(yield-current-task)) ; let the other fiber wait forever
;; This test relies on not draining -- this is the default,
;; but let's make this explicit.
#:drain? #false ;
;; For simplicity, disable concurrency and preemption.
;; That way, we can use 'yield-current-task' instead of an
;; arbitrary sleep time.
#:hz 0 #:parallelism 1)
(signal-condition! cv)))

(exit (if failed? 1 0))