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

Writing to a stdout pointing to /dev/full does not fail #5797

Closed
c4710n opened this issue Mar 19, 2022 · 3 comments
Closed

Writing to a stdout pointing to /dev/full does not fail #5797

c4710n opened this issue Mar 19, 2022 · 3 comments
Assignees
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Milestone

Comments

@c4710n
Copy link

c4710n commented Mar 19, 2022

Describe the bug
OTP allows writing to full device, but it shouldn't.

To Reproduce
Reproduce it on Linux:

$ erl -noshell -eval 'io:put_chars(standard_io, "hello world!\n").' -run init stop > /dev/full

/dev/full is a special device. It acts like a file on a filesystem that has just run out of space.

$ echo "Hello World!" > /dev/full
bash: echo: write error: No space left on device

Expected behavior
OTP can handle this condition as expected.

Affected versions
OTP 24, but other versions should be affected, too.

Additional context

@garazdawi
Copy link
Contributor

The reason why the error is not propagated is because of this function here. When sending data to the fd port, any error when trying to write is delivered by exit signal to the calling process. So a potentially correct fix could be to make put_port like this:

put_port(List, Port) ->
    true = port_command(Port, List),
    receive
        {'EXIT', Port, Reason} when Reason =/= normal ->
            Reason;
        after 0 ->
            ok
    end.

and also make sure to propagate the error all the way back.

@garazdawi garazdawi self-assigned this Mar 21, 2022
@garazdawi
Copy link
Contributor

garazdawi commented Apr 6, 2022

I had a look at trying to implement this and I don't think it is possible while still using the fd driver (that is a port started using {fd,0,1}) for stdin/stdout. This is because any error reporting is asynchronous and we do not know that the exit signal is in the mailbox of the calling process when the port_command returns. So the after in the code above would need to have some timeout value. It is impossible to know which value is short enough to work, and we do not want to have too long a value as any write would be delayed by that value.

So in conclusion, this bug cannot be fixed without taking a serious look at how the internals of the stdin/stdout handling works. It so happens that this is something that we are doing, so I'm leaving this issue to be fixed as part of that work.

@garazdawi garazdawi changed the title writing to a full device works Writing to a stdout pointing to /dev/full does not fail Apr 6, 2022
@garazdawi garazdawi added this to the OTP-26.0 milestone Apr 7, 2022
@garazdawi
Copy link
Contributor

Fixed in #6144

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is reported as a bug team:VM Assigned to OTP team VM
Projects
None yet
Development

No branches or pull requests

3 participants