Comments (3)
If you insert Lwt_unix.set_pool_size 0 ;
before the first Lwt_main.run
it will work. I Imagine Lwt starts a worker thread, which will not exist in the child process after the fork. With Lwt < 5, Lwt_unix.(set_default_async_method Async_none)
would also have done the trick.
More generally I have no idea why Lwt provides Lwt_unix.fork
given that (i) Lwt starts worker threads on encountering blocking system calls and (ii) threads and fork don't mix (all you can do in the child process after fork in a multi-threaded program is call async-signal-safe functions and then exec). Note that Unix.execv*
is not thread safe and cannot be used in multi-threaded programs either.
from lwt.
Possibly Lwt_unix.fork
is not thread safe either, because the documentation says that (as opposed to Unix.fork
) "in the child process all pending jobs are canceled", and I doubt that that can be achieved only by means of applying async-signal-safe functions.
from lwt.
If you insert
Lwt_unix.set_pool_size 0 ;
before the firstLwt_main.run
it will work. I Imagine Lwt starts a worker thread, which will not exist in the child process after the fork. With Lwt < 5,Lwt_unix.(set_default_async_method Async_none)
would also have done the trick.
Yes, it was our workaround to use Lwt_unix.(set_default_async_method Async_none)
in the child process.
More generally I have no idea why Lwt provides Lwt_unix.fork given that (i) Lwt starts worker threads on encountering blocking system calls and (ii) threads and fork don't mix (all you can do in the child process after fork in a multi-threaded program is call async-signal-safe functions and then exec). Note that Unix.execv* is not thread safe and cannot be used in multi-threaded programs either.
Yep, in the end we had to switch to lwt-parallel library instead of using fork directly. This library addresses this issue by creating a process snapshot before lwt is used. Probably, this is the only safe way of using Lwt_unix.fork
with lwt. We pushed some new features to lwt-parallel (including explicit snapshots). See ocaml/opam-repository#22611
from lwt.
Related Issues (20)
- Backtraces not propagated through `Lwt.catch` HOT 1
- OCaml 5.00 compatibility HOT 7
- Provide `Lwt.sleep` as a Unix-less function HOT 3
- Ppx_lwt docs link returns 404 error (since 5.4.0) HOT 1
- Drop support for OCaml < 4.08.0 HOT 4
- `src/unix/config/discover.exe` puts too much `-I` includes which can mislead the compiler
- EBADF from Lwt_process.with_* HOT 4
- Support `Lwt_process` in multi-domain settings HOT 1
- passing `env` in `Lwt_process` doesn't work on Windows HOT 1
- memory consumption blowups in downstream projects using Lwt HOT 5
- Ocaml 5 build issue HOT 3
- Default Unix pool size (1000) is insane and dangerous
- SIGSEGV on OCaml 5 due to missing SA_ONSTACK HOT 2
- Clarify documentation of Lwt_stream.get_available
- Have a separate set of `Lwt_process.pread` that also return the process status HOT 2
- Documentation of `Lwt_stream.create` and `Lwt_stream.get`
- Need a way to share SIGCHLD with other libraries HOT 2
- Race in worker_loop HOT 1
- Library not found for `-llwt_unix_stubs` on macOS HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lwt.