Skip to content

Commit 4fa38b8

Browse files
authored
Fix wings receiving wrong suspended status on sync (pterodactyl#3667)
Due to wings pulling the server configuration rather than the Panel pushing it, wings gets the wrong status for a server if both the status update and sync request are ran in a transaction due to the status not being persisted in the database. Fixes pterodactyl#3639
1 parent de0d5c9 commit 4fa38b8

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

app/Services/Servers/SuspensionService.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,20 @@ public function toggle(Server $server, $action = self::ACTION_SUSPEND)
5858
throw new ConflictHttpException('Cannot toggle suspension status on a server that is currently being transferred.');
5959
}
6060

61-
$this->connection->transaction(function () use ($action, $server, $isSuspending) {
61+
// Update the server's suspension status.
62+
$server->update([
63+
'status' => $isSuspending ? Server::STATUS_SUSPENDED : null,
64+
]);
65+
66+
try {
67+
// Tell wings to re-sync the server state.
68+
$this->daemonServerRepository->setServer($server)->sync();
69+
} catch (\Exception $exception) {
70+
// Rollback the server's suspension status if wings fails to sync the server.
6271
$server->update([
63-
'status' => $isSuspending ? Server::STATUS_SUSPENDED : null,
72+
'status' => $isSuspending ? null : Server::STATUS_SUSPENDED,
6473
]);
65-
66-
// Only trigger a Wings server sync if it is not currently being transferred.
67-
if (is_null($server->transfer)) {
68-
$this->daemonServerRepository->setServer($server)->sync();
69-
}
70-
});
74+
throw $exception;
75+
}
7176
}
7277
}

0 commit comments

Comments
 (0)