From 03c914f9e8897b15ae59ef6d102dea372a6d2320 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 2 May 2024 13:18:34 +0000 Subject: [PATCH] Fixed ragfair memory leak (!319) Fixed ragfair memory leak where NPC player ids would continuously get added into the cache map, when those offers expire the entry on the dictionary would be left empty but the string allocation on the key would remain in memory, overtime it would stack up to massive amounts of memory usage Co-authored-by: clodan Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/319 Co-authored-by: Alex Co-committed-by: Alex --- project/package.json | 2 +- project/src/ide/TestEntry.ts | 11 +++++++---- project/src/utils/RagfairOfferHolder.ts | 11 ++++++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/project/package.json b/project/package.json index 22c662fc..8df289bc 100644 --- a/project/package.json +++ b/project/package.json @@ -1,6 +1,6 @@ { "name": "aki-server", - "version": "3.8.0", + "version": "3.8.1", "author": "SPT-AKI Server", "license": "NCSA", "main": "obj/bundle.js", diff --git a/project/src/ide/TestEntry.ts b/project/src/ide/TestEntry.ts index e1ff4e4a..dc4ca2a9 100644 --- a/project/src/ide/TestEntry.ts +++ b/project/src/ide/TestEntry.ts @@ -2,7 +2,10 @@ import "reflect-metadata"; import "source-map-support/register"; import { Program } from "@spt-aki/Program"; -import * as buildInfo from "./build.json"; +// target run:profiler doesnt work with this here +// since this is the Test entry we can just remove +// it and leave those empty +// import * as buildInfo from "./build.json"; globalThis.G_DEBUG_CONFIGURATION = true; globalThis.G_RELEASE_CONFIGURATION = false; @@ -11,9 +14,9 @@ globalThis.G_MODS_TRANSPILE_TS = false; globalThis.G_LOG_REQUESTS = true; globalThis.G_WATERMARK_ENABLED = false; -globalThis.G_AKIVERSION = buildInfo.akiVersion; -globalThis.G_COMMIT = buildInfo.commit; -globalThis.G_BUILDTIME = buildInfo.buildTime; +globalThis.G_AKIVERSION = ""; +globalThis.G_COMMIT = ""; +globalThis.G_BUILDTIME = ""; const program = new Program(); program.start(); diff --git a/project/src/utils/RagfairOfferHolder.ts b/project/src/utils/RagfairOfferHolder.ts index 21367593..aa806efa 100644 --- a/project/src/utils/RagfairOfferHolder.ts +++ b/project/src/utils/RagfairOfferHolder.ts @@ -86,7 +86,16 @@ export class RagfairOfferHolder if (this.offersById.has(offer._id)) { this.offersById.delete(offer._id); - this.offersByTrader.get(offer.user.id).delete(offer._id); + const traderOffers = this.offersByTrader.get(offer.user.id); + traderOffers.delete(offer._id); + // This was causing a memory leak, we need to make sure that we remove + // the user ID from the cached offers after they dont have anything else + // on the flea placed. We regenerate the ID for the NPC users, making it + // continously grow otherwise + if (traderOffers.size === 0) + { + this.offersByTrader.delete(offer.user.id); + } this.offersByTemplate.get(offer.items[0]._tpl).delete(offer._id); } }