Skip to content

Commit 73761eb

Browse files
authored
VPN-7042: Fix shutdown/upgrade deadlock (#10520)
* Prevent multiple emissions of Controller::readyToQuit * Allow synchronous completion of TaskControllerAction * Only terminate GUI process with pkill during postinstall
1 parent 9f4d394 commit 73761eb

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

macos/pkg/scripts/postinstall.in

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ exec 2>&1 > $LOG_DIR/postinstall.log
3535
echo "Running postinstall at $(date)"
3636
echo "Installing Mozilla VPN to ${APP_DIR}"
3737

38-
pkill -x "Mozilla VPN" || echo "Unable to kill GUI, not running?"
38+
pkill -U "${USER}" -x "Mozilla VPN" || echo "Unable to kill GUI, not running?"
3939
sleep 1
4040

4141
## Before MacOS 13, take extra care to prevent tampering with the app.
@@ -62,8 +62,11 @@ echo "Codesign successful!"
6262

6363
# Unload the daemon
6464
UPDATING=
65-
if launchctl bootout system/${CODESIGN_APP_IDENTIFIER}.daemon 2>/dev/null; then
66-
echo "Update detected"
65+
if launchctl bootout system/${CODESIGN_APP_IDENTIFIER}.service 2>/dev/null; then
66+
echo "Update detected (SMAppService)"
67+
UPDATING=1
68+
elif launchctl bootout system/${CODESIGN_APP_IDENTIFIER}.daemon 2>/dev/null; then
69+
echo "Update detected (legacy daemon)"
6770
UPDATING=1
6871
fi
6972
if [ -f "$DAEMON_PLIST_PATH" ]; then

src/controller.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,12 @@ void Controller::quit() {
249249
logger.debug() << "Quitting";
250250

251251
if (!isActive()) {
252-
m_nextStep = Quit;
253252
emit readyToQuit();
254253
return;
255254
}
256255

257256
m_nextStep = Quit;
258-
259-
if (m_state == StateOn || m_state == StateOnPartial ||
260-
m_state == StateSwitching || m_state == StateSilentSwitching ||
261-
m_state == StateConnecting || m_state == StateConfirming) {
257+
if (m_state > StateDisconnecting) {
262258
deactivate();
263259
return;
264260
}

src/tasks/controlleraction/taskcontrolleraction.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ void TaskControllerAction::run() {
4242
Q_ASSERT(controller);
4343

4444
connect(controller, &Controller::stateChanged, this,
45-
&TaskControllerAction::stateChanged, Qt::QueuedConnection);
45+
&TaskControllerAction::stateChanged);
4646

47-
bool expectSignal = false;
47+
// Give the action some time to complete.
48+
m_timer.start(TASKCONTROLLER_TIMER_MSEC);
4849

50+
bool expectSignal = false;
4951
m_lastState = controller->state();
50-
5152
switch (m_action) {
5253
case eActivate:
5354
expectSignal = controller->activate(m_serverData);
@@ -70,15 +71,10 @@ void TaskControllerAction::run() {
7071
break;
7172
}
7273

73-
// No signal expected. Probably, the VPN is already in the right state. Let's
74-
// use the timer to wait 1 cycle only.
74+
// If no signal is expected, the VPN is probably already in the right state.
7575
if (!expectSignal) {
76-
m_timer.start(0);
77-
return;
76+
checkStatus();
7877
}
79-
80-
// Fallback 3 seconds.
81-
m_timer.start(TASKCONTROLLER_TIMER_MSEC);
8278
}
8379

8480
void TaskControllerAction::stateChanged() {

0 commit comments

Comments
 (0)