neovim-remote icon indicating copy to clipboard operation
neovim-remote copied to clipboard

nvr freezes if nvim is in background

Open jeremyjjbrown opened this issue 5 years ago • 6 comments

how to duplicate:

  1. open a nvim instance
  2. ctrl-z leave nvim
  3. list the servers
  4. send the server a remote command
  5. nvr hangs
  6. User is forced to ctrl-c and then exit nvim
10:08:20 ~
$ nvr --serverlist
/tmp/nvimX8iS8B/0

10:08:35 ~
$ nvr --servername /tmp/nvimX8iS8B/0  --remote-send '<Esc>:source $HOME/.config/nvim/init.vim<CR>'
^C
[!] Can't connect to: /tmp/nvimX8iS8B/0

    The server (nvim) and client (nvr) have to use the same address.

    Server:

        Expose $NVIM_LISTEN_ADDRESS to the environment before
        starting nvim:

        $ NVIM_LISTEN_ADDRESS=/tmp/nvimX8iS8B/0 nvim

        Use `:echo v:servername` to verify the address.

        Security: When using Unix domain sockets on a multi-user system,
        the socket should have proper permissions so that it is only
        accessible by your user.

    Client:

        Expose $NVIM_LISTEN_ADDRESS to the environment before
        using nvr or use its --servername option. If neither
        is given, nvr assumes "/tmp/nvimsocket".

        $ NVIM_LISTEN_ADDRESS=/tmp/nvimX8iS8B/0 nvr file1 file2
        $ nvr --servername /tmp/nvimX8iS8B/0 file1 file2
        $ nvr --servername 127.0.0.1:6789 file1 file2

    nvr is now starting a server on its own by running $NVR_CMD or 'nvim'.

    Use -s to suppress this message.

[*] Starting new nvim process with address /tmp/nvimX8iS8B/0


11:08:53 ~
$ NVIM_LISTEN_ADDRESS=/tmp/nvimX8iS8B/0 nvr  --remote-send '<Esc>:source $HOME/.config/nvim/init.vim<CR>'
^C
[!] Can't connect to: /tmp/nvimX8iS8B/0

    The server (nvim) and client (nvr) have to use the same address.

    Server:

        Expose $NVIM_LISTEN_ADDRESS to the environment before
        starting nvim:

        $ NVIM_LISTEN_ADDRESS=/tmp/nvimX8iS8B/0 nvim

        Use `:echo v:servername` to verify the address.

        Security: When using Unix domain sockets on a multi-user system,
        the socket should have proper permissions so that it is only
        accessible by your user.

    Client:

        Expose $NVIM_LISTEN_ADDRESS to the environment before
        using nvr or use its --servername option. If neither
        is given, nvr assumes "/tmp/nvimsocket".

        $ NVIM_LISTEN_ADDRESS=/tmp/nvimX8iS8B/0 nvr file1 file2
        $ nvr --servername /tmp/nvimX8iS8B/0 file1 file2
        $ nvr --servername 127.0.0.1:6789 file1 file2

    nvr is now starting a server on its own by running $NVR_CMD or 'nvim'.

    Use -s to suppress this message.

[*] Starting new nvim process with address /tmp/nvimX8iS8B/0

versions

11:16:36 ~
$ nvr --version
nvr 2.1.7

11:16:40 ~
$ bash --version
GNU bash, version 5.0.2(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

11:16:47 ~
$ nvim --version
NVIM v0.3.4
Build type: Release
LuaJIT 2.0.5
Compilation: /usr/bin/cc -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -Wconversion -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -Wno-array-bounds -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/build/neovim/src/build/config -I/build/neovim/src/neovim-0.3.4/src -I/usr/include -I/build/neovim/src/build/src/nvim/auto -I/build/neovim/src/build/include
Compiled by builduser

Features: +acl +iconv +jemalloc +tui 
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

11:17:02 ~
$ python --version
Python 3.7.3

OS's: Arch Linux and MacOS Mojave

jeremyjjbrown avatar Apr 03 '19 16:04 jeremyjjbrown

Confirmed! Looking into it the next days.

mhinz avatar Apr 06 '19 19:04 mhinz

What I forgot to ask: What behavior do you actually expect?

It seems to work correctly. When nvim is suspended, then nvr will wait until nvim's socket returns any data. When you foreground the process again, nvr will finish immediately.

The actual networking work happens in pynvim and its dependencies. nvr really just uses pynvim's attach() function. Maybe I could add some kind of warning message when attach() didn't finish after 3 seconds or so, but the behavior would stay the same.

When you then hit <c-c>, it means that no connection could be made and thus nvr starts a new nvim process. You can avoid that with the --nostart option.

mhinz avatar May 01 '19 19:05 mhinz

A workflow which I would like to have is being able to suspend nvim and opening another file via nvr in the suspended nvim-instance as usual. Currently nvr freezes if I try to open a file with nvr in a suspended nvim-instance. If I press <c-c> after nvr freezes nvim opens with an empty buffer. If I close it and enter fg to return to the old nvim-instance the file which I tried to open via nvr is opened in the nvim-instance. This is annoying. Would be really cool if this would work without the freezing part.

astier avatar May 18 '19 11:05 astier

@astier You can just background it. it will open the file once you bring nvim to the forground. I wrote a script for this https://github.com/EvanPurkhiser/dots-personal/blob/master/base/bash/functions.d/vim-singleton

evanpurkhiser avatar May 30 '19 05:05 evanpurkhiser

"What I forgot to ask: What behavior do you actually expect?"

I expect if Ctrl-Z out of nvim and later use nvr send it a cmd to that it does it without hanging me up in another nvim instance I don't want. Perhaps it's not simple because the nvim is in SIGTSTP. In that case I would spawn a process with some reasonable timeout that would send the message as soon as the process is awake.

jeremyjjbrown avatar Jun 13 '19 14:06 jeremyjjbrown

@EvanPurkhiser thx for the suggestion. (nvr --nostart "$@" &) basically does the trick. I think it still would be nice if this would work out of the box.

astier avatar Oct 09 '19 15:10 astier