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

v2: "canceling" blocking syscalls on macOS does not truly cancel them #136

Open
robbielyman opened this issue Sep 21, 2024 · 0 comments
Open

Comments

@robbielyman
Copy link
Owner

robbielyman commented Sep 21, 2024

it's not completely clear to me how important this issue is, but it is an issue.

for example, the CLI interface has a recurring call to read from stdin.
this call may be "canceled" on the event loop in two situations:
one, where the program is exiting due to some condition other than the user typing "quit" in the REPL,
and two, where the TUI interface is launched.
in each situation on macOS, the call to read is executing on a different thread, which stays blocked in that call.

there are two instances where this becomes an issue:
under normal execution, if any thread is blocked (say in read), calling seamstress.pool.deinit() will block too,
since it tries to join the thread.
strictly speaking, cleaning up the thread pool is not a prerequisite for exiting the program,
but i could see this becoming an issue if many zombie threads accumulate,
say in a hot-reload situation.

the other is that when running tests via zig build test, the test runner is run in "server" mode,
which appears to not exit whenever any test has active threads remaining?
it's not clear to me how this is accomplished, but it is true that if i delete the following lines in Seamstress.deinit

seamstress.pool.shutdown();
seamstress.pool.deinit();

the test runner will still fail to exit.


potential solutions include wrapping the call to read in a poll which includes a self-pipe for terminating the thread, or looking into alternate solutions for the event loop. might actually be time to read some of Node.js's source lol

robbielyman added a commit that referenced this issue Sep 22, 2024
…he thread loop

by using kqueue, reading from stdin will happen only when there is
data to read. this allows canceling the operation to actually cancel
the poll, rather than leave the call to `read` blocked indefinitely.

closes #136
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant