Skip to content

Conversation

@justinmk
Copy link
Member

@justinmk justinmk commented Sep 13, 2019

$NVIM_LISTEN_ADDRESS has two conflicting purposes:

  1. Set the initial server address at startup.
  2. Expose the server address of the current Nvim .

To fix that, $NVIM_LISTEN_ADDRESS was deprecated, and --listen was introduced.

The next step is to introduce $NVIM which only exposes the address of the current Nvim. This gives :terminal children a way to communicate with the parent (again, $NVIM_LISTEN_ADDRESS cannot be used for that because that conflicts with existing usages of it to set the server at startup).

This also fixes the "Failed to start server" spam that was in our test logs:

2022-05-02… WARN … server_start:154: Failed to start server: address already in use: …/Xtest_tmpdir/test/functional/nvimtbuxco/0
2022-05-02… WARN … server_start:154: Failed to start server: address already in use: …/Xtest_tmpdir/test/functional/nvimtbuxco/0

Fixes #3118
Fixes #6764
Fixes #9336

See also:

@bfredl
Copy link
Member

bfredl commented Jan 31, 2020

@justinmk Is there anything blocking this from being merged? I think we should move forward on the connection code quite soon, including the first remote TUI step, which is quite low-risk. (though a quite relative "soon", I will fix outstanding extmark bugs before focusing on this. But I think others might be interested in working on it).

@wsdjeg
Copy link
Contributor

wsdjeg commented Jan 31, 2020

@justinmk why do not jut keep $NVIM_LISTEN_ADDRESS, change $NVIM_LISTEN_ADDRESS to $NVIM will break compatibe, BTW, in vim, the $VIM is the path of where vim is installed. it will make user confuse.

@teto teto added this to the 0.6 milestone Nov 1, 2020
matheuristic added a commit to matheuristic/dotfiles that referenced this pull request Nov 20, 2020
- Modify s:preventNestedNeovim() in Neovim configuration so that
  it checks both the $NVIM (planned) and $NVIM_LISTEN_ADDRESS
  (deprecated) for the address of a parent Neovim session, if any.
  See neovim/neovim#11009 for details.
matheuristic added a commit to matheuristic/dotfiles that referenced this pull request Nov 20, 2020
- Some details around implementation of $NVIM environment variable
  in neovim/neovim#11009 are still not
  finalized. Wait for finalization before changing function.
matheuristic added a commit to matheuristic/dotfiles that referenced this pull request Nov 20, 2020
- Some details around implementation of $NVIM environment variable
  in neovim/neovim#11009 are still not
  finalized. Wait for finalization before changing function.
matheuristic added a commit to matheuristic/dotfiles that referenced this pull request Nov 20, 2020
- Some details around implementation of $NVIM environment variable
  in neovim/neovim#11009 are still not
  finalized. Wait for finalization before changing function.
@ddickstein
Copy link
Contributor

ddickstein commented Mar 1, 2021

@justinmk can you confirm that NVIM_LISTEN_ADDRESS will not be removed until NVIM is available (that is, that there won't be a point where functionality (2) - Expose the server address of the current Nvim - is lost)?

@bfredl bfredl modified the milestones: 0.6, 0.7 Nov 27, 2021
@neovim neovim deleted a comment from neovim-discourse Apr 17, 2022
@justinmk justinmk changed the title introduce $NVIM introduce $NVIM, unset $VIM, $VIMRUNTIME in children May 2, 2022
justinmk added a commit to neovim/node-client that referenced this pull request May 2, 2022
Use $NVIM with Nvim 0.8+.

Since neovim/neovim#11009 (Nvim 0.8+) the
correct way to detect a "host" or "parent" Nvim is to check for $NVIM
env var: this means node is a child of that process.

The old $NVIM_LISTEN_ADDRESS env var had conflicting purposes as both
a parameter ("set --listen to this address") and a descriptor ("the
current process is a child of this address").
justinmk added a commit to neovim/node-client that referenced this pull request May 2, 2022
Use $NVIM with Nvim 0.8+.

Since neovim/neovim#11009 (Nvim 0.8+) the
correct way to detect a "host" or "parent" Nvim is to check for $NVIM
env var: this means node is a child of that process.

The old $NVIM_LISTEN_ADDRESS env var had conflicting purposes as both
a parameter ("set --listen to this address") and a descriptor ("the
current process is a child of this address").
justinmk added a commit to neovim/node-client that referenced this pull request May 2, 2022
Use $NVIM with Nvim 0.8+.

Since neovim/neovim#11009 (Nvim 0.8+) Nvim does
_not_ pass $NVIM_LISTEN_ADDRESS to child processes.  The correct way to
detect a "host" or "parent" Nvim is to check for $NVIM env var: this
means the current process is a child of Nvim.

The old $NVIM_LISTEN_ADDRESS env var had conflicting purposes as both
a parameter ("the current process should _listen on_ this address") and
a descriptor ("the current process is a _child of_ this address").
@justinmk justinmk force-pushed the nvim-env branch 3 times, most recently from f9d8c8e to 86d12e0 Compare May 2, 2022 21:31
PROBLEM
------------------------------------------------------------------------
$NVIM_LISTEN_ADDRESS has conflicting purposes as both a parameter ("the
current process should listen on this address") and a descriptor ("the
current process is a child of this address").

This contradiction means the presence of NVIM_LISTEN_ADDRESS is
ambiguous, so child Nvim always tries to listen on its _parent's_
socket. This is the cause of lots of  "Failed to start server" spam in
our test/CI logs:

    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-4480-0
    WARN  2022-04-30… server_start:154: Failed to start server: address already in use: \\.\pipe\nvim-2168-0

SOLUTION
------------------------------------------------------------------------

1. Set $NVIM to the parent v:servername, *only* in child processes.
   - Now the correct way to detect a "parent" Nvim is to check for $NVIM.
2. Do NOT set $NVIM_LISTEN_ADDRESS in child processes.
3. On startup if $NVIM_LISTEN_ADDRESS exists, unset it immediately after
   server init.
4. Open a channel to parent automatically, expose it as v:parent.

Fixes neovim#3118
Fixes neovim#6764
Fixes neovim#9336
Ref neovim#8247 (comment)
Ref neovim#8696
@justinmk justinmk changed the title introduce $NVIM, unset $VIM, $VIMRUNTIME in children introduce $NVIM, unset $NVIM_LISTEN_ADDRESS May 3, 2022
@justinmk
Copy link
Member Author

justinmk commented May 3, 2022

Merging this and will continue the remaining items in other PRs. (The freebsd failure looks unrelated and similar to other PRs).

can you confirm that NVIM_LISTEN_ADDRESS will not be removed until NVIM is available

Confirmed, $NVIM is available to all child processes of Nvim started by jobstart() and :terminal.

@justinmk justinmk merged commit 4fb48c5 into neovim:master May 3, 2022
@justinmk justinmk deleted the nvim-env branch May 3, 2022 13:08
@neovim neovim locked as resolved and limited conversation to collaborators May 3, 2022
@zeertzjq zeertzjq modified the milestones: 0.9, 0.8 Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

job-control OS processes, spawn server listen

Projects

None yet

7 participants