fix memory leak on SIGHUP

This commit is contained in:
Miko 2025-01-31 12:01:09 +01:00
parent 1d60dd6afc
commit a245126c20
3 changed files with 26 additions and 2 deletions

View file

@ -6,6 +6,7 @@ export const serve_rendered = {
init: (options, repo, programOpts) => {}, init: (options, repo, programOpts) => {},
add: (options, repo, params, id, programOpts, dataResolver) => {}, add: (options, repo, params, id, programOpts, dataResolver) => {},
remove: (repo, id) => {}, remove: (repo, id) => {},
clear: (repo) => {},
getTerrainElevation: (data, param) => { getTerrainElevation: (data, param) => {
param['elevation'] = 'not supported in light'; param['elevation'] = 'not supported in light';
return param; return param;

View file

@ -15,7 +15,6 @@ import '@maplibre/maplibre-gl-native';
import advancedPool from 'advanced-pool'; import advancedPool from 'advanced-pool';
import path from 'path'; import path from 'path';
import url from 'url'; import url from 'url';
import util from 'util';
import sharp from 'sharp'; import sharp from 'sharp';
import clone from 'clone'; import clone from 'clone';
import Color from 'color'; import Color from 'color';
@ -1458,7 +1457,25 @@ export const serve_rendered = {
} }
delete repo[id]; delete repo[id];
}, },
/**
* Removes all items from the repository.
* @param {object} repo Repository object.
* @returns {void}
*/
clear: function (repo) {
Object.keys(repo).forEach((id) => {
const item = repo[id];
if (item) {
item.map.renderers.forEach((pool) => {
pool.close();
});
item.map.renderersStatic.forEach((pool) => {
pool.close();
});
}
delete repo[id];
});
},
/** /**
* Get the elevation of terrain tile data by rendering it to a canvas image * Get the elevation of terrain tile data by rendering it to a canvas image
* @param {object} data The background color (or empty string for transparent). * @param {object} data The background color (or empty string for transparent).

View file

@ -743,6 +743,7 @@ async function start(opts) {
app, app,
server, server,
startupPromise, startupPromise,
serving,
}; };
} }
/** /**
@ -777,8 +778,13 @@ export async function server(opts) {
running.server.shutdown(async () => { running.server.shutdown(async () => {
const restarted = await start(opts); const restarted = await start(opts);
if (!isLight) {
serve_rendered.clear(running.serving.rendered);
}
running.server = restarted.server; running.server = restarted.server;
running.app = restarted.app; running.app = restarted.app;
running.startupPromise = restarted.startupPromise;
running.serving = restarted.serving;
}); });
}); });
return running; return running;