Skip to content

Commit 1f73d63

Browse files
authored
QProcess cleanup #1076
Try to softly shutdown QProcess instances or allow the QProcess destructor to SIGKILL. The major change are the calls to setparent that result in the underlying qprocess being removed by the destructor (killing the nvim process). For the GUI close event we first try to wait 500ms for the process to terminate (this may have to be tuned). Tests were adjusted to make this a bit easier to manage with a QSharedPointer, the main reason for this was the issues we see in windows with leftover process breaking CI. There is still some flakyness in the tests, with occasional failures, but at least tests succeed more often now. No doubt that the root cause for races in tests is still present. Given the issues we saw with CI, I have removed all github CI windows. Troubleshooting them was always hard and some tests systematically failed.
2 parents 8c9c02d + 5441d1b commit 1f73d63

File tree

14 files changed

+78
-113
lines changed

14 files changed

+78
-113
lines changed

.github/workflows/build-test.yml

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,6 @@ jobs:
4949
cc: clang
5050
cxx: clang++
5151
publish: true
52-
53-
# Qt 5.15 only supports MinGW 8.11. The `windows-latest` and `windows-2022`
54-
# images bundle only 11.2. For now, we must use the older image `windows-2019`.
55-
- name: Windows_MingGW
56-
flavor: Debug
57-
runner: windows-2022
58-
generator: MinGW Makefiles
59-
qtver: 5.15.2
60-
qtdir: mingw81_64
61-
qtstr: windows desktop win64_mingw81
62-
cc: gcc
63-
cxx: g++
64-
ctest_exe_args: -tap
65-
66-
- name: Windows_Release
67-
flavor: Release
68-
runner: windows-2022
69-
generator: Visual Studio 17 2022
70-
qtver: 5.15.2
71-
qtdir: msvc2019_64
72-
qtstr: windows desktop win64_msvc2019_64
73-
ctest_exe_args: -tap
74-
publish: true
75-
7652
runs-on: ${{ matrix.runner }}
7753
steps:
7854
- uses: actions/checkout@v2
@@ -96,33 +72,6 @@ jobs:
9672
brew ls --formula | grep -wq msgpack || brew install msgpack
9773
brew link qt5 --force
9874
99-
- name: Windows - Setup
100-
if: ${{ startsWith(matrix.runner, 'windows') }}
101-
env:
102-
QT_DIR: ${{ github.workspace }}\${{ matrix.qtver }}\${{ matrix.qtdir }}
103-
run: |
104-
New-Item -Path .\build -Name "build" -ItemType "directory"
105-
Invoke-WebRequest https://github.com/neovim/neovim/releases/download/stable/nvim-win64.zip -OutFile nvim-win64.zip
106-
Expand-Archive -Path nvim-win64.zip -DestinationPath .\build\
107-
Add-Content -Path $env:GITHUB_PATH -Value ${{ github.workspace }}\build\nvim-win64\bin\
108-
Add-Content -Path $env:GITHUB_ENV -Value "CMAKE_PREFIX_PATH=$env:QT_DIR;$env:QT_DIR\lib\cmake"
109-
Add-Content -Path $env:GITHUB_PATH -Value "${{ env.qt_dir }}"
110-
Add-Content -Path $env:GITHUB_PATH -Value "${{ env.qt_dir }}\bin"
111-
112-
- name: Qt Cache Restore
113-
if: ${{ matrix.qtver }}
114-
id: cache-qt
115-
uses: actions/cache@v2
116-
with:
117-
path: ${{ matrix.qtver }}\${{ matrix.qtdir }}
118-
key: qt-${{ runner.os }}-${{ matrix.qtver }}-${{ matrix.qtdir }}
119-
120-
- name: Qt Cache Install
121-
if: ${{ matrix.qtver && steps.cache-qt.outputs.cache-hit != 'true' }}
122-
run: |
123-
pip install aqtinstall
124-
python -m aqt install ${{ matrix.qtver }} ${{ matrix.qtstr }}
125-
12675
#
12776
# Build and Test
12877
#
@@ -169,16 +118,6 @@ jobs:
169118
macdeployqt ./build/bin/nvim-qt.app -dmg
170119
mv ./build/bin/nvim-qt.dmg neovim-qt.dmg
171120
172-
- name: Windows - Publish
173-
if: ${{ matrix.publish && startsWith(matrix.runner, 'windows') }}
174-
run: |
175-
cmake --build ./build --target install
176-
Push-Location ${{ github.workspace }}/build
177-
cpack --verbose -G WIX
178-
Pop-Location
179-
Compress-Archive -Path ./install -DestinationPath neovim-qt.zip
180-
Move-Item -Path ./build/neovim-qt-installer.msi -Destination neovim-qt-installer.msi
181-
182121
- name: Upload Artifacts
183122
if: ${{ matrix.publish }}
184123
uses: actions/upload-artifact@v2

contrib/appveyor.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ environment:
1010
GENERATOR: MinGW Makefiles
1111
RELEASE_ARTIFACT: true
1212
CMAKE_PATH_PREFIX: C:\Qt\5.15\mingw81_64\lib\cmake
13+
CMAKE_BUILD_TYPE: Release
1314
- PlatformToolset: VisualStudio2019
1415
QTPATH: C:\Qt\5.15\msvc2019_64
1516
GENERATOR: Visual Studio 16
1617
CMAKE_PATH_PREFIX: C:\Qt\5.15\msvc2019_64\lib\cmake
18+
CMAKE_BUILD_TYPE: Debug
1719
- PlatformToolset: MinGW-Win64-Qt6
1820
QTPATH: C:\Qt\6.2.4\mingw_64
1921
GENERATOR: MinGW Makefiles
2022
RELEASE_ARTIFACT: false
2123
CMAKE_PATH_PREFIX: C:\Qt\6.2.4\mingw_64\lib\cmake
2224
EXTRA_CMAKE_ARGS: -DWITH_QT=Qt6
25+
CMAKE_BUILD_TYPE: Release
2326
configuration:
2427
- RelWithDebInfo
2528
matrix:
@@ -42,7 +45,7 @@ build_script:
4245
- echo %PATH%
4346
- mkdir build
4447
- cd build
45-
- cmake -G "%GENERATOR%" -DCMAKE_PREFIX_PATH="%CMAKE_PATH_PREFIX%" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../INSTALL -DENABLE_TESTS=ON %EXTRA_CMAKE_ARGS% ..
48+
- cmake -G "%GENERATOR%" -DCMAKE_PREFIX_PATH="%CMAKE_PATH_PREFIX%" -DCMAKE_BUILD_TYPE=%CMAKE_BUILD_TYPE% -DCMAKE_INSTALL_PREFIX=../INSTALL -DENABLE_TESTS=ON %EXTRA_CMAKE_ARGS% ..
4649
- cmake --build . --config Release --target install
4750
- cpack --verbose -G WIX
4851
test_script:

src/gui/mainwindow.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "mainwindow.h"
22

33
#include <QCloseEvent>
4+
#include <QEventLoop>
45
#include <QLayout>
56
#include <QSettings>
67
#include <QStyleFactory>
@@ -42,11 +43,11 @@ void MainWindow::init(NeovimConnector *c)
4243
}
4344

4445
m_shell = new Shell(c);
46+
m_shell->setParent(this);
4547

4648
addToolBar(&m_tabline);
4749

4850
m_nvim = c;
49-
m_nvim->setParent(this);
5051

5152
// GuiShowContextMenu - right click context menu and actions.
5253
m_contextMenu = new ContextMenu(c, this);
@@ -235,6 +236,18 @@ void MainWindow::neovimGuiCloseRequest(int status)
235236
{
236237
m_neovim_requested_close = true;
237238
m_exitStatus = status;
239+
240+
// Try to wait for neovim to quit
241+
QTimer timer;
242+
timer.setSingleShot(true);
243+
QEventLoop loop;
244+
connect(m_nvim, &NeovimConnector::processExited, &loop, &QEventLoop::quit);
245+
connect(m_nvim, &NeovimConnector::aboutToClose, &loop, &QEventLoop::quit);
246+
timer.start(500);
247+
loop.exec();
248+
bool timed_out = !timer.isActive();
249+
qDebug() << "Waited for neovim close, timed out:" << timed_out;
250+
238251
QMainWindow::close();
239252
m_neovim_requested_close = false;
240253
}

src/gui/shell.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ Shell::Shell(NeovimConnector *nvim, QWidget *parent)
9292
return;
9393
}
9494

95+
m_nvim->setParent(this);
96+
9597
connect(m_nvim, &NeovimConnector::error,
9698
this, &Shell::neovimError);
9799
connect(m_nvim, &NeovimConnector::processExited,

src/gui/shell.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class Shell: public ShellWidget
7070
static void DispatchRedrawNotifications(
7171
T* pThis, const QVariantList& args) noexcept;
7272

73+
NeovimConnector* nvim() { return m_nvim; }
7374
signals:
7475
void neovimTitleChanged(const QString &title);
7576
void neovimBusyChanged(bool);

src/msgpackiodevice.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ MsgpackIODevice::MsgpackIODevice(QIODevice* dev, QObject* parent)
6060
m_dev->setParent(this);
6161
connect(m_dev, &QAbstractSocket::readyRead,
6262
this, &MsgpackIODevice::dataAvailable);
63+
connect(m_dev, &QIODevice::aboutToClose, this, &MsgpackIODevice::aboutToClose);
6364

6465
if ( !m_dev->isSequential() ) {
6566
setError(InvalidDevice, tr("IO device needs to be sequential"));

src/msgpackiodevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class MsgpackIODevice: public QObject
7171
/** A notification with the given name and arguments was received */
7272
void notification(const QByteArray &name, const QVariantList& args);
7373
void encodingChanged(const QByteArray& encoding);
74+
void aboutToClose();
7475

7576
protected:
7677
void sendError(const msgpack_object& req, const QString& msg);

src/neovimconnector.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ NeovimConnector::NeovimConnector(MsgpackIODevice *dev)
3737

3838
connect(m_dev, &MsgpackIODevice::error,
3939
this, &NeovimConnector::msgpackError);
40+
connect(m_dev, &MsgpackIODevice::aboutToClose, this, &NeovimConnector::aboutToClose);
41+
42+
m_dev->setParent(this);
4043

4144
if ( !m_dev->isOpen() ) {
4245
return;

src/neovimconnector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class NeovimConnector: public QObject
106106
void ready();
107107
void error(NeovimQt::NeovimConnector::NeovimError);
108108
void processExited(int exitCode);
109+
void aboutToClose();
109110

110111
public slots:
111112
void fatalTimeout();

test/common_gui.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ template<class T> static void ValidateNeovimConnection(T* obj) noexcept
3535
Q_ASSERT(obj->isNeovimAttached());
3636
}
3737

38-
std::pair<NeovimConnector*, Shell*> CreateShellWidget() noexcept
38+
QSharedPointer<Shell> CreateShellWidget() noexcept
3939
{
4040
DisableLocalGInitVim();
4141
NeovimConnector* c{ NeovimConnector::spawn(cs_argsNone) };
@@ -45,10 +45,10 @@ std::pair<NeovimConnector*, Shell*> CreateShellWidget() noexcept
4545

4646
ValidateNeovimConnection(s);
4747

48-
return { c, s };
48+
return QSharedPointer<Shell>(s);
4949
}
5050

51-
std::pair<NeovimConnector*, MainWindow*> CreateMainWindow() noexcept
51+
QSharedPointer<MainWindow> CreateMainWindow() noexcept
5252
{
5353
NeovimConnector* c{ NeovimConnector::spawn(cs_argsNone) };
5454
MainWindow* w{ new MainWindow{ c } };
@@ -57,10 +57,10 @@ std::pair<NeovimConnector*, MainWindow*> CreateMainWindow() noexcept
5757

5858
ValidateNeovimConnection(w);
5959

60-
return { c, w };
60+
return QSharedPointer<MainWindow>(w);
6161
}
6262

63-
std::pair<NeovimConnector*, MainWindow*> CreateMainWindowWithRuntime() noexcept
63+
QSharedPointer<MainWindow> CreateMainWindowWithRuntime() noexcept
6464
{
6565
static const QStringList cs_argsNoneRuntime{
6666
"-u", "NONE", "--cmd", "set rtp+=" + GetRuntimeAbsolutePath()
@@ -74,7 +74,7 @@ std::pair<NeovimConnector*, MainWindow*> CreateMainWindowWithRuntime() noexcept
7474

7575
ValidateNeovimConnection(w);
7676

77-
return { c, w };
77+
return QSharedPointer<MainWindow>(w);
7878
}
7979

8080
} // namespace NeovimQt

0 commit comments

Comments
 (0)