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

Problem with STDOUT after non-zero exit of crystal binary in script #5731

Closed
keriwarr opened this issue Feb 19, 2018 · 6 comments
Closed

Problem with STDOUT after non-zero exit of crystal binary in script #5731

keriwarr opened this issue Feb 19, 2018 · 6 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib

Comments

@keriwarr
Copy link

$ crystal -v
Crystal 0.24.1 (2018-01-27)

LLVM: 5.0.1
Default target: x86_64-apple-macosx

Steps to reproduce

execute the following commands in your terminal (I've reproduced on sh, bash, and zsh):

echo "exit 1" > foo.cr
crystal build foo.cr
echo "#\!/bin/bash\n./foo\nfor i in {1..5000}; do echo -n \"\$i \"; done" > bar.sh
chmod 775 bar.sh
./bar.sh

Note: you may need to run ./bar.sh multiple times

expected behaviour

bar.sh prints numbers 1 to 5000

actual behaviour

bar.sh behaves erratically, usually failing to print most numbers, echo occasionally printing errors.

details

In general, I observe this behaviour any time that within a script a crystal-compiled program is executed, and returns non-zero, then a substantial amount of text is printed to STDOUT.

I don't think I understand enough about binaries/STDIN/STDOUT/whatever to get much further on debugging this myself :)

@ysbaddaden
Copy link
Contributor

Duplicate of #2713 (with incomplete workaround in #5017) ?

@RX14
Copy link
Contributor

RX14 commented Feb 19, 2018

Ah yes, seems like we need a restore_blocking_state in exit. I'd say this is a separate bug report on the code in #5017.

And as always I maintain that STDIN and STDOUT should be left blocking as it is semantically wrong to change the blocking state on them.

@RX14 RX14 added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib labels Feb 19, 2018
@keriwarr
Copy link
Author

keriwarr commented Feb 19, 2018

Duplicate of #2713

Ah, sorry about that, I saw that ticket but didn't manage to figure out a workaround so I figured it could be different.

As a work-around, I can just put this at the start of every program?

STDIN.blocking = true
STDOUT.blocking = true
STDERR.blocking = true

@RX14
Copy link
Contributor

RX14 commented Feb 19, 2018

@keriwarr for now, yes. Or always call Crystal.restore_blocking_state before exit. Or use at_exit { Crystal.restore_blocking_state }

@asterite
Copy link
Member

I think this is fixed now (at least the offending code now seems to work fine)

@RX14
Copy link
Contributor

RX14 commented Jul 20, 2018

Fixed by #5802

@RX14 RX14 closed this as completed Jul 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib
Projects
None yet
Development

No branches or pull requests

4 participants