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

catch requests from invalid thread #255

Merged
merged 2 commits into from
Nov 2, 2018
Merged

Conversation

bfredl
Copy link
Member

@bfredl bfredl commented Apr 14, 2017

No description provided.

neovim/api/nvim.py Outdated Show resolved Hide resolved
@phmarek
Copy link

phmarek commented Apr 15, 2017

request was make from a non-main thread:
  File "/usr/lib/python3/dist-packages/neovim-0.1.14.dev0-py3.5.egg/neovim/plugin/script_host.py", line 226, in find_spec
    return PathFinder.find_spec(fullname, path or _get_paths(), target)
  File "/usr/lib/python3/dist-packages/neovim-0.1.14.dev0-py3.5.egg/neovim/plugin/script_host.py", line 190, in _get_paths
    return discover_runtime_directories(nvim)
  File "/usr/lib/python3/dist-packages/neovim-0.1.14.dev0-py3.5.egg/neovim/plugin/script_host.py", line 239, in discover_runtime_directories
    for path in nvim.list_runtime_paths():
  File "/usr/lib/python3/dist-packages/neovim-0.1.14.dev0-py3.5.egg/neovim/api/nvim.py", line 251, in list_runtime_paths
    return self.request('nvim_list_runtime_paths')

And then some follow-ups:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "~/.config/nvim/bundle/YouCompleteMe/autoload/../python/ycm/client/base_request.py", line 144, in Session
    return cls.session
AttributeError: type object 'BaseRequest' has no attribute 'session'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "~/.config/nvim/bundle/YouCompleteMe/autoload/../python/ycm/client/base_request.py", line 216, in HandleServerException
    yield
  File "~/.config/nvim/bundle/YouCompleteMe/autoload/../python/ycm/client/ycmd_keepalive.py", line 50, in _ThreadMain
    BaseRequest.GetDataFromHandler( 'healthy' )
  File "~/.config/nvim/bundle/YouCompleteMe/autoload/../python/ycm/client/base_request.py", line 70, in GetDataFromHandler
    timeout ) )
  File "~/.config/nvim/bundle/YouCompleteMe/autoload/../python/ycm/client/base_request.py", line 110, in _TalkToHandlerAsync
    return BaseRequest.Session().get(
  File "~/.config/nvim/bundle/YouCompleteMe/autoload/../python/ycm/client/base_request.py", line 147, in Session
    from requests_futures.sessions import FuturesSession
  File "~/.config/nvim/bundle/YouCompleteMe/third_party/requests-futures/requests_futures/sessions.py", line 24, in <module>
    from requests import Session
  File "~/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/requests/requests/__init__.py", line 53, in <module>
    from .packages.urllib3.contrib import pyopenssl
  File "~/.config/nvim/bundle/YouCompleteMe/third_party/ycmd/third_party/requests/requests/packages/urllib3/contrib/pyopenssl.py", line 49, in <module>
    from ndg.httpsclient.ssl_peer_verification import SUBJ_ALT_NAME_SUPPORT
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 954, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 896, in _find_spec
  File "<frozen importlib._bootstrap_external>", line 1147, in find_spec
  File "<frozen importlib._bootstrap_external>", line 1121, in _get_spec
  File "/usr/lib/python3/dist-packages/neovim-0.1.14.dev0-py3.5.egg/neovim/plugin/script_host.py", line 226, in find_spec
    return PathFinder.find_spec(fullname, path or _get_paths(), target)
  File "/usr/lib/python3/dist-packages/neovim-0.1.14.dev0-py3.5.egg/neovim/plugin/script_host.py", line 190, in _get_paths
    return discover_runtime_directories(nvim)
  File "/usr/lib/python3/dist-packages/neovim-0.1.14.dev0-py3.5.egg/neovim/plugin/script_host.py", line 239, in discover_runtime_directories
    for path in nvim.list_runtime_paths():
  File "/usr/lib/python3/dist-packages/neovim-0.1.14.dev0-py3.5.egg/neovim/api/nvim.py", line 251, in list_runtime_paths
    return self.request('nvim_list_runtime_paths')
  File "/usr/lib/python3/dist-packages/neovim-0.1.14.dev0-py3.5.egg/neovim/api/nvim.py", line 137, in request
    raise NvimError("request was made from a non-main thread")
neovim.api.nvim.NvimError: request was made from a non-main thread
During handling of the above exception, another exception occurred:
...

@bfredl
Copy link
Member Author

bfredl commented Apr 16, 2017

It seems that the import path hook is not thread safe, we'll need to either disallow path_hook imports on threads or use a cached copy of rtp.

@bfredl
Copy link
Member Author

bfredl commented Apr 16, 2017

Please try latest commit

@phmarek
Copy link

phmarek commented Apr 17, 2017

Looks good so far.... when merging, please keep the first commit too, so that the problem can be more easily diagnosed later on.

Thank you!

@bfredl bfredl merged commit 0852da8 into neovim:master Nov 2, 2018
@justinmk justinmk changed the title [WIP] catch requests from invalid thread catch requests from invalid thread Nov 2, 2018
@@ -165,6 +166,15 @@ def request(self, name, *args, **kwargs):
present and True, a asynchronous notification is sent instead. This
will never block, and the return value or error is ignored.
"""
if (self._session._loop_thread is not None and
threading.current_thread() != self._session._loop_thread):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this use self._thread_invalid() ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants