mirage-solo5 icon indicating copy to clipboard operation
mirage-solo5 copied to clipboard

Lwt.pause deadlock on spt

Open Firobe opened this issue 5 months ago • 5 comments

open Lwt.Syntax

module Hello (T : Mirage_time.S) = struct
    let f1c = ref 0
    let f2c = ref 0

    let rec f1 () = 
        Logs.info (fun f -> f "f1 (%d)" !f1c);
        incr f1c;
        let* () = Lwt.pause () in
        f1 ()

    let rec f2 () = 
        Logs.info (fun f -> f "f2 (%d)" !f2c);
        incr f2c;
        let* () = Lwt.pause () in
        f2 ()

    let start _ =
        Logs.info (fun f -> f "Start");
        let* _ = Lwt.all [f1 (); f2 ()] in Lwt.return_unit
end

The above unikernel, when compiled and executed for the hvt target, produces the expected output:

2024-09-19T09:27:21-00:00: [INFO] [application] Start
2024-09-19T09:27:21-00:00: [INFO] [application] f2 (0)
2024-09-19T09:27:21-00:00: [INFO] [application] f1 (0)
2024-09-19T09:27:21-00:00: [INFO] [application] f2 (1)
2024-09-19T09:27:21-00:00: [INFO] [application] f1 (1)
2024-09-19T09:27:21-00:00: [INFO] [application] f2 (2)
2024-09-19T09:27:21-00:00: [INFO] [application] f1 (2)
2024-09-19T09:27:21-00:00: [INFO] [application] f2 (3)
2024-09-19T09:27:21-00:00: [INFO] [application] f1 (3)
2024-09-19T09:27:21-00:00: [INFO] [application] f2 (4)
2024-09-19T09:27:21-00:00: [INFO] [application] f1 (4)
2024-09-19T09:27:21-00:00: [INFO] [application] f2 (5)
2024-09-19T09:27:21-00:00: [INFO] [application] f1 (5)
2024-09-19T09:27:21-00:00: [INFO] [application] f2 (6)
2024-09-19T09:27:21-00:00: [INFO] [application] f1 (6)
2024-09-19T09:27:21-00:00: [INFO] [application] f2 (7)
2024-09-19T09:27:21-00:00: [INFO] [application] f1 (7)
2024-09-19T09:27:21-00:00: [INFO] [application] f2 (8)
2024-09-19T09:27:21-00:00: [INFO] [application] f1 (8)
[...]

However when compiled and executed for the spt target, fibers that have have "paused" are never woken up, and the application deadlocks:

2024-09-19T09:32:32-00:00: [INFO] [application] Start
2024-09-19T09:32:32-00:00: [INFO] [application] f2 (0)
2024-09-19T09:32:32-00:00: [INFO] [application] f1 (0)
[no further logs]

Firobe avatar Sep 19 '24 09:09 Firobe