Skip to content

Escripts crash when run under nohup #10397

@AWMcLeod

Description

@AWMcLeod

Describe the bug
Using nohup to run an escript that writes to stdout causes the process to hang, generating the following error message:

=CRASH REPORT==== 20-Nov-2025::13:41:44.320735 ===
  crasher:
    initial call: prim_tty:reader/1
    pid: <0.69.0>
    registered_name: user_drv_reader
    exception error: no case clause matching {error,{read,ebadf}}
      in function  prim_tty:reader_loop/6 (prim_tty.erl, line 531)
    ancestors: [user_drv,<0.65.0>,kernel_sup,<0.47.0>]
    message_queue_len: 0
    messages: []
    links: [<0.66.0>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 233
    stack_size: 29
    reductions: 50
  neighbours:

=ERROR REPORT==== 20-Nov-2025::13:41:44.330581 ===
Reader crashed ({{case_clause,{error,{read,ebadf}}},
                 [{prim_tty,reader_loop,6,[{file,"prim_tty.erl"},{line,531}]},
                  {proc_lib,init_p_do_apply,3,
                            [{file,"proc_lib.erl"},{line,329}]}]})
Failed to write log message to stdout, trying stderr
=CRASH REPORT==== 20-Nov-2025::13:41:44.320735 ===
  crasher:
    initial call: prim_tty:reader/1
    pid: <0.69.0>
    registered_name: user_drv_reader
    exception error: no case clause matching {error,{read,ebadf}}
      in function  prim_tty:reader_loop/6 (prim_tty.erl, line 531)
    ancestors: [user_drv,<0.65.0>,kernel_sup,<0.47.0>]
    message_queue_len: 0
    messages: []
    links: [<0.66.0>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 233
    stack_size: 29
    reductions: 50
  neighbours:

Failed to write log message to stdout, trying stderr
=ERROR REPORT==== 20-Nov-2025::13:41:44.330581 ===
Reader crashed ({{case_clause,{error,{read,ebadf}}},
                 [{prim_tty,reader_loop,6,[{file,"prim_tty.erl"},{line,531}]},
                  {proc_lib,init_p_do_apply,3,
                            [{file,"proc_lib.erl"},{line,329}]}]})

To Reproduce
See the following trivial reproduction:

-module(main).
-export([main/1]).

main(_) ->
        io:fwrite("Hello World!\n").

Then attempt to execute this file via escript and nohup I.e.

$ nohup escript main.erl

nohup: ignoring input and appending output to 'nohup.out'
^C
ott-ads-381:~/nb/erlang $ cat nohup.out
=CRASH REPORT==== 20-Nov-2025::13:41:44.320735 ===
  crasher:
    initial call: prim_tty:reader/1
    pid: <0.69.0>
    registered_name: user_drv_reader
    exception error: no case clause matching {error,{read,ebadf}}
      in function  prim_tty:reader_loop/6 (prim_tty.erl, line 531)
    ancestors: [user_drv,<0.65.0>,kernel_sup,<0.47.0>]
    message_queue_len: 0
    messages: []
    links: [<0.66.0>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 233
    stack_size: 29
    reductions: 50
  neighbours:

=ERROR REPORT==== 20-Nov-2025::13:41:44.330581 ===
Reader crashed ({{case_clause,{error,{read,ebadf}}},
                 [{prim_tty,reader_loop,6,[{file,"prim_tty.erl"},{line,531}]},
                  {proc_lib,init_p_do_apply,3,
                            [{file,"proc_lib.erl"},{line,329}]}]})
Failed to write log message to stdout, trying stderr
=CRASH REPORT==== 20-Nov-2025::13:41:44.320735 ===
  crasher:
    initial call: prim_tty:reader/1
    pid: <0.69.0>
    registered_name: user_drv_reader
    exception error: no case clause matching {error,{read,ebadf}}
      in function  prim_tty:reader_loop/6 (prim_tty.erl, line 531)
    ancestors: [user_drv,<0.65.0>,kernel_sup,<0.47.0>]
    message_queue_len: 0
    messages: []
    links: [<0.66.0>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 233
    stack_size: 29
    reductions: 50
  neighbours:

Failed to write log message to stdout, trying stderr
=ERROR REPORT==== 20-Nov-2025::13:41:44.330581 ===
Reader crashed ({{case_clause,{error,{read,ebadf}}},
                 [{prim_tty,reader_loop,6,[{file,"prim_tty.erl"},{line,531}]},
                  {proc_lib,init_p_do_apply,3,
                            [{file,"proc_lib.erl"},{line,329}]}]})

Expected behavior
A crash would not be expected here. In this case, the Hello World text should instead be captured in nohup.out, and the escript should have terminated gracefully.

Affected versions
Erlang/OTP 27.3.4.6

Additional context
This is not observed in Erlang/OTP 28.0.

Manual bisection suggests that this issue was resolved in 28.0 via the refactor found in #8962

Metadata

Metadata

Assignees

Labels

bugIssue is reported as a bugteam:VMAssigned to OTP team VM

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions