8000 Prevent third-party plugins with faulty hooks to crash the server by ccordoba12 · Pull Request #158 · python-lsp/python-lsp-server · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions pylsp/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

import logging
from functools import lru_cache
import pkg_resources
from typing import List, Mapping, Sequence, Union

import pkg_resources
import pluggy
from pluggy._hooks import HookImpl

from pylsp import _utils, hookspecs, uris, PYLSP

Expand All @@ -16,6 +18,24 @@
DEFAULT_CONFIG_SOURCES = ['pycodestyle']


class PluginManager(pluggy.PluginManager):

def _hookexec(
self,
hook_name: str,
methods: Sequence[HookImpl],
kwargs: Mapping[str, object],
firstresult: bool,
) -> Union[object, List[object]]:
# called from all hookcaller instances.
# enable_tracing will set its own wrapping function at self._inner_hookexec
try:
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
except Exception as e: # pylint: disable=broad-except
log.warning(f"Failed to load hook {hook_name}: {e}")
return []


class Config:
def __init__(self, root_uri, init_opts, process_id, capabilities):
self._root_path = uris.to_fs_path(root_uri)
Expand All @@ -39,7 +59,7 @@ def __init__(self, root_uri, init_opts, process_id, capabilities):
except ImportError:
pass

self._pm = pluggy.PluginManager(PYLSP)
self._pm = PluginManager(PYLSP)
self._pm.trace.root.setwriter(log.debug)
self._pm.enable_tracing()
self._pm.add_hookspecs(hookspecs)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ python_requires = >=3.7
install_requires =
jedi>=0.17.2,<0.19.0
python-lsp-jsonrpc>=1.0.0
pluggy
pluggy>=1.0.0
ujson>=3.0.0
setuptools>=39.0.0
setup_requires = setuptools>=44; wheel; setuptools_scm[toml]>=3.4.3
Expand Down
0