router(server): fix panic on server deletion

Fixes https://github.com/pterodactyl/panel/issues/5028

Signed-off-by: Matthew Penner <me@matthewp.io>
This commit is contained in:
Matthew Penner 2024-03-13 14:46:17 -06:00
parent d649bb1116
commit 99b9924a4a
No known key found for this signature in database

View File

@ -227,20 +227,19 @@ func deleteServer(c *gin.Context) {
//
// In addition, servers with large amounts of files can take some time to finish deleting,
// so we don't want to block the HTTP call while waiting on this.
go func(p string) {
_ = s.Filesystem().UnixFS().Close()
go func(s *server.Server) {
fs := s.Filesystem()
p := fs.Path()
_ = fs.UnixFS().Close()
if err := os.RemoveAll(p); err != nil {
log.WithFields(log.Fields{"path": p, "error": err}).Warn("failed to remove server files during deletion process")
}
}(s.Filesystem().Path())
}(s)
middleware.ExtractManager(c).Remove(func(server *server.Server) bool {
return server.ID() == s.ID()
})
// Deallocate the reference to this server.
s = nil
c.Status(http.StatusNoContent)
}