{"action":"created","issue":{"url":"https://api.github.com/repos/ocsigen/lwt/issues/121","labels_url":"https://api.github.com/repos/ocsigen/lwt/issues/121/labels{/name}","comments_url":"https://api.github.com/repos/ocsigen/lwt/issues/121/comments","events_url":"https://api.github.com/repos/ocsigen/lwt/issues/121/events","html_url":"https://github.com/ocsigen/lwt/issues/121","id":57155923,"number":121,"title":"Lwt_unix.sleep thread not waking up","user":{"login":"zoggy","id":515002,"avatar_url":"https://avatars.githubusercontent.com/u/515002?v=3","gravatar_id":"","url":"https://api.github.com/users/zoggy","html_url":"https://github.com/zoggy","followers_url":"https://api.github.com/users/zoggy/followers","following_url":"https://api.github.com/users/zoggy/following{/other_user}","gists_url":"https://api.github.com/users/zoggy/gists{/gist_id}","starred_url":"https://api.github.com/users/zoggy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zoggy/subscriptions","organizations_url":"https://api.github.com/users/zoggy/orgs","repos_url":"https://api.github.com/users/zoggy/repos","events_url":"https://api.github.com/users/zoggy/events{/privacy}","received_events_url":"https://api.github.com/users/zoggy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-02-10T10:27:01Z","updated_at":"2015-02-12T18:12:16Z","closed_at":null,"body":"Hello,\r\n\r\nI have a problem using Lwt_unix.sleep. I cannot reduce to a small example so I describe the observed behaviour, if someone can give me clues about what's going on.\r\n\r\nI have various Lwt.t threads sleeping for 2 seconds, doing things, then waiting again, in a recursive function. At the beginning, everything is fine, threads wake up every 2 seconds, do what they have to do, then recursively call the function to sleep again and so on.\r\n\r\nAfter some wake ups, there is a kind of pause during several seconds with no threads waking up (but going to sleep). Then they wake up again. Then pause again and then one of them is not waken up. After some time, another one is not waken up, then another one until no thread seems to be waken up.\r\n\r\nMoreoever, I observe this when I have 2 or 4 threads, but everything is ok when I have 1 or 3. With 5 threads some disappear (don't seem to wake up), then reappear again...\r\n\r\nAny idea of what could be wrong ?  \r\n\r\nThe problem is the same when the threads do nothing between the calls to Lwt_unix.sleep."},"comment":{"url":"https://api.github.com/repos/ocsigen/lwt/issues/comments/74121442","html_url":"https://github.com/ocsigen/lwt/issues/121#issuecomment-74121442","issue_url":"https://api.github.com/repos/ocsigen/lwt/issues/121","id":74121442,"user":{"login":"avsm","id":53164,"avatar_url":"https://avatars.githubusercontent.com/u/53164?v=3","gravatar_id":"","url":"https://api.github.com/users/avsm","html_url":"https://github.com/avsm","followers_url":"https://api.github.com/users/avsm/followers","following_url":"https://api.github.com/users/avsm/following{/other_user}","gists_url":"https://api.github.com/users/avsm/gists{/gist_id}","starred_url":"https://api.github.com/users/avsm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avsm/subscriptions","organizations_url":"https://api.github.com/users/avsm/orgs","repos_url":"https://api.github.com/users/avsm/repos","events_url":"https://api.github.com/users/avsm/events{/privacy}","received_events_url":"https://api.github.com/users/avsm/received_events","type":"User","site_admin":false},"created_at":"2015-02-12T18:12:16Z","updated_at":"2015-02-12T18:12:16Z","body":"The bug happens without nocrypto.  I've distilled it down to two files:\r\n\r\nfoo.ml:\r\n```\r\nopen Lwt\r\n\r\nlet () =                                                                                       \r\n  let _ = Lwt_engine.on_timer 2.0 true @@ fun _ ->\r\n      prerr_endline \"on_timer\";                              \r\n  in ()\r\n```\r\n\r\nand the `bar.ml` of\r\n\r\n```\r\nopen Lwt.Infix\r\n\r\nlet sleep_duration = 1.0\r\nlet debug = fun s -> Lwt_io.write Lwt_io.stderr (s^\"\\n\")\r\n\r\nlet rec wait f =\r\n  Lwt.catch\r\n    (fun () ->\r\n       debug (Printf.sprintf \"sleeping for %f\" sleep_duration) >>= fun () ->\r\n         Lwt_unix.sleep sleep_duration >>= fun () ->\r\n         debug \"doing thing... \" >>= fun _ ->\r\n         f () >>= fun _ -> wait f\r\n    )\r\n    (fun e ->\r\n       prerr_endline (Printf.sprintf \"wait: %s\" (Printexc.to_string e));\r\n       wait f\r\n    )\r\n;;\r\nlet () = Lwt_engine.set (new Lwt_engine.select);;\r\nLwt_unix.run (Lwt.join\r\n [\r\n   wait (fun () -> debug \"thread 1\") ;\r\n   wait (fun () -> debug \"thread 2\") ;\r\n   wait (fun () -> debug \"thread 3\") ;\r\n   wait (fun () -> debug \"thread 4\") ;\r\n   wait (fun () -> debug \"thread 5\") ;\r\n   wait (fun () -> debug \"thread 6\") ;\r\n ])\r\n```\r\n\r\nIf compiled with both linked in (so that the Lwt_engine calls both happen), e.g.\r\n\r\n```\r\nocamlfind ocamlopt -annot -o lwtsleep -annot -package lwt.unix -linkpkg foo.ml bar.ml\r\n```"}}