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 <clodan@clodan.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/319
Co-authored-by: Alex <clodan@noreply.dev.sp-tarkov.com>
Co-committed-by: Alex <clodan@noreply.dev.sp-tarkov.com>
This commit is contained in:
Alex 2024-05-02 13:18:34 +00:00 committed by chomp
parent bccda0302f
commit 03c914f9e8
3 changed files with 18 additions and 6 deletions

View File

@ -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",

View File

@ -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();

View File

@ -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);
}
}