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

Channels opened by sockconnect() does not close automatically on EOF #11166

Open
alaviss opened this issue Oct 6, 2019 · 3 comments
Open

Channels opened by sockconnect() does not close automatically on EOF #11166

alaviss opened this issue Oct 6, 2019 · 3 comments

Comments

@alaviss
Copy link

alaviss commented Oct 6, 2019

  • nvim --version:

    NVIM v0.4.2
    Build type: Release
    LuaJIT 2.0.5
    Compilation: /usr/bin/x86_64-pc-linux-gnu-gcc -O3 -march=native -pipe -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/tmp/portage/app-editors/neovim-0.4.2/work/neovim-0.4.2_build/config -I/tmp/portage/app-editors/neovim-0.4.2/work/neovim-0.4.2/src -I/usr/include -I/tmp/portage/app-editors/neovim-0.4.2/work/neovim-0.4.2_build/src/nvim/auto -I/tmp/portage/app-editors/neovim-0.4.2/work/neovim-0.4.2_build/include
    Compiled by portage@workstation
    
    Features: +acl +iconv +tui
    See ":help feature-compile"
    
       system vimrc file: "/etc/vim/sysinit.vim"
      fall-back for $VIM: "/usr/share/nvim"
    
    Run :checkhealth for more info
    
  • Operating system/version: Gentoo

  • Terminal name/version: alacritty 0.3.3

  • $TERM: alacritty

Steps to reproduce using nvim -u NORC

  1. Make an auto-disconnecting TCP server:
import net

var server = newSocket()
server.bindAddr 8000.Port, "localhost"
server.listen()

var client: Socket
while true:
  server.accept client
  close client
  1. Reproduce the problem
nvim -u NORC
:echo sockconnect('tcp', 'localhost:8000', {})
<returns channel id>
:echo nvim_list_chans()

Actual behaviour

The returned channel is still in the list. lsof will report that the socket held by nvim is in CLOSE_WAIT state.

A walkaround is to close the channel manually via the handler on EOF.

Expected behaviour

The channel should be closed.

@alaviss alaviss added the bug issues reporting wrong behavior label Oct 6, 2019
alaviss added a commit to alaviss/nim.nvim that referenced this issue Oct 6, 2019
@justinmk justinmk added this to the 0.5 milestone Oct 6, 2019
@janlazo janlazo modified the milestones: 0.5, 0.5.1 Feb 14, 2021
@justinmk justinmk modified the milestones: 0.5.1, 0.5.2 Sep 26, 2021
@justinmk justinmk modified the milestones: 0.7.1, 0.7.2 Jun 26, 2022
@justinmk
Copy link
Member

Still present on b7084fe

Python version:

import socket

serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind(('localhost', 8000))
serversocket.listen(5)

while True:
    (clientsocket, address) = serversocket.accept()
    serversocket.close()

@zeertzjq zeertzjq modified the milestones: 0.8.1, 0.8.2 Nov 14, 2022
@justinmk justinmk added has:repro issue contains minimal reproducing steps complexity:low Low-risk, self-contained. Do NOT ask "can I work on this", just read CONTRIBUTING.md labels Dec 11, 2022
@zeertzjq zeertzjq modified the milestones: 0.8.2, 0.8.3 Dec 29, 2022
@tmccombs
Copy link
Contributor

tmccombs commented Feb 2, 2023

FWIW, I don't think this happens if you include an on_data function in the third argument to sockconnect.

@alaviss
Copy link
Author

alaviss commented Feb 4, 2023

After a while, I think this behavior is correct. It prevents a class of bug where the channel id is reused but a stale one is held elsewhere before cleanup occurs (ie. in a dict).

There should probably be documentation to remind users that they have to close the channel once they're done with it. I believe I got the assumption that the channel auto closes from :h channel_buffered.

channel-buffered The callback is invoked immediately as data is available, where a single-item list [''] indicates EOF (stream closed).

@zeertzjq zeertzjq modified the milestones: 0.8.3, 0.8.4 Feb 11, 2023
@zeertzjq zeertzjq modified the milestones: 0.9.1, 0.9.2 May 26, 2023
@zeertzjq zeertzjq modified the milestones: 0.9.2, 0.9.3 Sep 2, 2023
@zeertzjq zeertzjq modified the milestones: 0.9.3, 0.9.4 Oct 9, 2023
@zeertzjq zeertzjq removed bug issues reporting wrong behavior complexity:low Low-risk, self-contained. Do NOT ask "can I work on this", just read CONTRIBUTING.md labels Dec 23, 2023
@zeertzjq zeertzjq removed the has:repro issue contains minimal reproducing steps label Dec 23, 2023
@zeertzjq zeertzjq modified the milestones: 0.9.5, backlog Dec 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants