Skip to content

read in config.fish gives input_initialized=false while it should be true #4199

Closed

Description

@tomsmeding

OS: macOS Sierra & Arch Linux
$TERM = xterm-256color

First noticed in the Fish 2.6.0 release, but a git bisect tells us that the commit that introduced the error is 6d02bec. Note that in particular, Fish 2.5.0 is before that commit and is fine.

Like the title says, if the file ~/.config/fish/config.fish contains an executed call to the read builtin, the global variable input_initialized is at some point during execution of that file, set to false. This means that afterwards, fish crashes with an assertion error on the line assert(input_initialized); in src/reader.cpp.

How to reproduce: in a plain new fish installation checked out at 6d02bec, create a ~/.config/fish/config.fish with the contents:

read kaas

Then start a new shell. It will prompt for input with read>, and after reading a line, crash with the stacktrace: (recorded after exchanging -O2 for -g in the Makefile makes and recompiling for a more useful trace)

<E> fish: src/reader.cpp:1542: failed assertion: input_initialized
<E> fish: Backtrace:
<E> fish: 0   reader_interactive_init() + 60
<E> fish: 1   reader_push(wchar_t const*) + 374
<E> fish: 2   read_i() + 23
<E> fish: 3   reader_read(int, io_chain_t const&) + 168
<E> fish: 4   main + 1459
<E> fish: 5   start + 1

A run in lldb with a watchpoint set on input_initialized (lldb ./fish, b main, process launch -t, wa s v input_initialized, cont, cont, then enter something in the read> prompt, then bt) shows that it is set to false with the following backtrace: (I entered "hoi")

* thread #1: tid = 0x146840, 0x00000001001554bd fish`input_destroy() + 29 at input.cpp:315, queue = 'com.apple.main-thread', stop reason = watchpoint 1
  * frame #0: 0x00000001001554bd fish`input_destroy() + 29 at input.cpp:315
    frame #1: 0x00000001001e1864 fish`reader_interactive_destroy() + 148 at reader.cpp:1647
    frame #2: 0x00000001001e1776 fish`reader_pop() + 342 at reader.cpp:2017
    frame #3: 0x000000010003f2d6 fish`read_interactive(buff=L"hoi", nchars=0, shell=false, mode_name=L"fish_read", prompt=L"set_color green; echo -n read; set_color normal; echo -n \"> \"", right_prompt=L"", commandline=L"") + 3046 at builtin.cpp:1991
    frame #4: 0x0000000100020e2c fish`builtin_read(parser=0x000000010025a230, streams=0x0000000100506530, argv=0x0000000100506050) + 4172 at builtin.cpp:2266
    frame #5: 0x0000000100011b65 fish`builtin_run(parser=0x000000010025a230, argv=0x0000000100506050, streams=0x0000000100506530) + 501 at builtin.cpp:3583
    frame #6: 0x00000001000f7aa7 fish`exec_job(parser=0x000000010025a230, j=0x0000000100506488) + 12519 at exec.cpp:802
    frame #7: 0x000000010018f3c8 fish`parse_execution_context_t::run_1_job(this=0x0000000100505f80, job_node=0x000000010081a614, associated_block=0x0000000100505ff0) + 4696 at parse_execution.cpp:1311
    frame #8: 0x000000010018f74b fish`parse_execution_context_t::run_job_list(this=0x0000000100505f80, job_list_node=0x000000010081a600, associated_block=0x0000000100505ff0) + 283 at parse_execution.cpp:1345
    frame #9: 0x000000010019a3d5 fish`parse_execution_context_t::eval_node_at_offset(this=0x0000000100505f80, offset=0, associated_block=0x0000000100505ff0, io=0x00007fff5fbfbc88) + 1381 at parse_execution.cpp:1384
    frame #10: 0x00000001001c1784 fish`parser_t::eval_block_node(this=0x000000010025a230, node_idx=0, io=0x00007fff5fbfbc88, block_type=TOP) + 628 at parser.cpp:662
    frame #11: 0x00000001001c1079 fish`parser_t::eval(this=0x000000010025a230, cmd=L"read kaas\n", io=0x00007fff5fbfbc88, block_type=TOP, tree=parse_node_tree_t @ 0x00007fff5fbfa4e0) + 1529 at parser.cpp:621
    frame #12: 0x00000001001f06aa fish`read_ni(fd=3, io=0x00007fff5fbfbc88) + 3242 at reader.cpp:3306
    frame #13: 0x00000001001ef08c fish`reader_read(fd=3, io=0x00007fff5fbfbc88) + 188 at reader.cpp:3344
    frame #14: 0x0000000100023ccc fish`builtin_source(parser=0x000000010025a230, streams=0x0000000100507080, argv=0x00000001005067b0) + 1836 at builtin.cpp:2848
    frame #15: 0x0000000100011b65 fish`builtin_run(parser=0x000000010025a230, argv=0x00000001005067b0, streams=0x0000000100507080) + 501 at builtin.cpp:3583
    frame #16: 0x00000001000f7aa7 fish`exec_job(parser=0x000000010025a230, j=0x0000000100506328) + 12519 at exec.cpp:802
    frame #17: 0x000000010018f3c8 fish`parse_execution_context_t::run_1_job(this=0x0000000100507be0, job_node=0x0000000100802a14, associated_block=0x00000001005078f0) + 4696 at parse_execution.cpp:1311
    frame #18: 0x000000010018f74b fish`parse_execution_context_t::run_job_list(this=0x0000000100507be0, job_list_node=0x0000000100802a00, associated_block=0x00000001005078f0) + 283 at parse_execution.cpp:1345
    frame #19: 0x000000010019a3d5 fish`parse_execution_context_t::eval_node_at_offset(this=0x0000000100507be0, offset=0, associated_block=0x00000001005078f0, io=0x00007fff5fbff0c0) + 1381 at parse_execution.cpp:1384
    frame #20: 0x00000001001c1784 fish`parser_t::eval_block_node(this=0x000000010025a230, node_idx=0, io=0x00007fff5fbff0c0, block_type=TOP) + 628 at parser.cpp:662
    frame #21: 0x00000001001c1079 fish`parser_t::eval(this=0x000000010025a230, cmd=L"builtin source /Users/Tom/.config/fish/config.fish", io=0x00007fff5fbff0c0, block_type=TOP, tree=parse_node_tree_t @ 0x00007fff5fbfeeb0) + 1529 at parser.cpp:621
    frame #22: 0x00000001001bef28 fish`parser_t::eval(this=0x000000010025a230, cmd=L"builtin source /Users/Tom/.config/fish/config.fish", io=0x00007fff5fbff0c0, block_type=TOP) + 968 at parser.cpp:596
    frame #23: 0x000000010022e5be fish`source_config_in_directory(dir=L"/Users/Tom/.config/fish") + 766 at fish.cpp:197
    frame #24: 0x000000010022d7ec fish`read_init(paths=0x00007fff5fbff4c8) + 220 at fish.cpp:211
    frame #25: 0x000000010022a14f fish`main(argc=1, argv=0x00007fff5fbff9f0) + 863 at fish.cpp:367
    frame #26: 0x00007fffa6e2a235 libdyld.dylib`start + 1

Most testing was performed on my macOS machine, but the crash is at least also observed in Arch Linux with Fish 2.6.0. Since the backtrace is the same, I have assumed here that it is the same problem and that it isn't very system-specific.

Note that calling the read builtin in the interactive prompt gives no problems, it is specifically calling it in config.fish that results in the crash.

From the above stacktrace, my hunch is that the read builtin is setting up and tearing down an interactive context as if it's in a nice separate process, while it's actually overriding the global context of the interactive process. Any ideas?

(Possibly related issue: #4178)

Activity

  1. krader1961 commented on Jul 7, 2017

    @krader1961
    Contributor

    This is a dup of #4178 and possibly other bugs involving fish process group management.

  2. zanchey commented on Jul 7, 2017

    @zanchey
    Member

    @krader1961, for my own education, how did you decide this was a dupe?

  3. krader1961 commented on Jul 7, 2017

    @krader1961
    Contributor

    It's the second failure mode the O.P. in that issue reported. It's not identical to the read < /dev/tty case in my stripped down test case but is probably closely related.

  4. tomsmeding commented on Jul 8, 2017

    @tomsmeding
    ContributorAuthor

    Personally, I don't see how this is related to process groups; I'd rather say this would be fixed either by stacking interactive contexts (making input_initialized an int that is incremented/decremented instead of being set to 1 or 0), or by having read correctly check that it's actually in a separate process and not running in the same process as the interactive shell. Note that this seems related to job management in general and not specifically to process groups; but of course I can be wrong.

    I do see that the second error reported in the linked issue is equal to the one reported here.

  5. mqudsi commented on Sep 15, 2017

    @mqudsi
    Contributor

    I'm re-opening this because while the second bug described in #4178 is the same, this one actually provides a test case and #4178 is describing two distinct bugs. This will make it easier to keep track of both.

    Additionally, while the OP in #4178 describes both, the comments thereafter including @krader1961's test case are for reproducing only the first bug described, which does not involve the assertion failure described here.

  6. reopened this on Sep 15, 2017
  7. added
    bug
    and removed on Mar 7, 2018
  8. IsaacOscar commented on Mar 11, 2018

    @IsaacOscar
    Contributor

    Strange, I can't reproduce this on my system:

    ~> fish --version
    fish, version 2.7.1-934-g9a5afe3
    ~> uname -a
    Linux fisher 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
    ~> echo $TERM
    xterm-256color
    ~> echo -e '\x05'
    ~> PuTTY
    
  9. mqudsi commented on Sep 30, 2018

    @mqudsi
    Contributor

    @tomsmeding

    Note that this seems related to job management in general and not specifically to process groups; but of course I can be wrong.

    Control of the terminal is assigned to a single process group at a time. Even if the process itself does not have control of the terminal (controlling pgid != pid) if it is part of the same group that is led by the process in control of the terminal, it will work.

  10. mqudsi commented on Sep 30, 2018

    @mqudsi
    Contributor

    No longer reproduces in master.

  11. added this to the fish-3.0 milestone on Oct 1, 2018
  12. locked as resolved and limited conversation to collaborators on Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions