Protect the access to module path for executable cache

The getPylsModulePath() may be called concurrently:
PyLSConfigureAssistant::openDocumentWithPython() ->
runAsync -> checkPythonLanguageServer() ->
getPylsModulePath(), so protect the access to the
static cache by mutex.

Amends: 54f2ebf91d

Change-Id: Ia88a9e680b092bcc7cf62338387775521d497835
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Jarek Kobus
2021-06-15 14:23:15 +02:00
parent 905f5d4e1b
commit d4c36f43b0

View File

@@ -98,6 +98,8 @@ static QString pythonName(const FilePath &pythonPath)
FilePath getPylsModulePath(CommandLine pylsCommand) FilePath getPylsModulePath(CommandLine pylsCommand)
{ {
static QMutex mutex; // protect the access to the cache
QMutexLocker locker(&mutex);
static QMap<FilePath, FilePath> cache; static QMap<FilePath, FilePath> cache;
const FilePath &modulePath = cache.value(pylsCommand.executable()); const FilePath &modulePath = cache.value(pylsCommand.executable());
if (!modulePath.isEmpty()) if (!modulePath.isEmpty())