Skip to content

Commit

Permalink
router(server): fix panic on server deletion
Browse files Browse the repository at this point in the history
Fixes pterodactyl/panel#5028

Signed-off-by: Matthew Penner <[email protected]>
  • Loading branch information
matthewpi committed Mar 13, 2024
1 parent d649bb1 commit 99b9924
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions router/router_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 99b9924

Please sign in to comment.