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

Pony sets stdin to nonblocking, breaking almost every program not expecting it. #205

Closed
Earnestly opened this issue May 16, 2015 · 3 comments

Comments

@Earnestly
Copy link

Edit: Removing the calls to fd_nonblocking() inside os_stdin_setup()
corrects this apparent broken behaviour but I have no idea what kind of
consequence that has.

Edit2: This may be related to the handling of non-blocking stdin internally,
this is usually accomplished with e/poll() and select() while stdfd.c
doesn't appear to use anything from aiso.h.

Edit3: It's likely because you set stdin to NONBLOCK which breaks many
programs out there which don't handle, or need to handle, non-blocking stdin.
The need to use non-blocking stdin is also curious given the use of epoll and
blocking fd probably being more power friendly as well.

Edit4: This probably applies to stdout and stderr as well. Perhaps you should
not be setting them to non-blocking as it will break almost any filter program
too

A Bit of Background

The build system for Arch Linux -- makepkg -- is written in in bash.

As part of the build system you can install any missing dependencies, build
dependencies and test dependencies which will later be removed at the end.

As part of this process pacman (called via makepkg) will offer a confirmation
prompt to the user and ask if they would like to remove the target packages.

After the commit 07d9453 I had started to
notice this prompt would be skipped, essentially stdin was missing.

A Test Case

I have managed to reproduce this with a minimal pony program consisting of
just a main actor and an environment:

actor Main
    new create(env: Env) =>
        None

And a test script:

#!/usr/bin/env bash

./pony_test

read -p "Prompt: " result
printf '%s\n' "$result"

Running this results in the following error:

# Bash
Prompt: test.bash: line 5: read: read error: 0: Resource temporarily unavailable

# Dash (It just exits, nothing is read.)
Prompt: 

Addendum

The same thing works fine with zsh, albeit adjusting the read to match the
syntax of zsh (read "?Prompt: " result), however zsh seems to always try
again if the result of the call to read() sets errno EAGAIN. (It also
seems to set the fd to O_NONBLOCK).

In both Bash and Dash the errno is also set to EAGAIN but they don't try
again.

Here is a temporary snippet for strace output on both Zsh and Bash just after
the pony program ends: http://ix.io/iAT

References

@Earnestly Earnestly changed the title Pony breaks stdin when used in scripts and other software. Pony sets stdin to nonblocking, breaking almost every program not expecting it. May 16, 2015
@Earnestly
Copy link
Author

Also, please rename the title to something more appropriate because I am
struggling to find a succinct and short introduction for the true error here.

@sylvanc
Copy link
Contributor

sylvanc commented May 17, 2015

The title sums it up pretty well!

Thanks for the report. I just pushed what might be a fix for this. It seems to work for me on OSX and Linux - can you please give it a try and see if it works for you?

@Earnestly
Copy link
Author

Yep, commit c5090ad fixes this issue appropriately, thanks.

jemc pushed a commit that referenced this issue Jul 5, 2016
Many programs (like cat) cannot handle non-blocking file descriptors.
This was causing a sporadic failure in the process monitor tests.

This is similar to issue #205.
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

2 participants