fix memory leak on SIGHUP (#1455)

This commit is contained in:
Miko 2025-02-06 21:55:09 +01:00 committed by GitHub
parent 1d60dd6afc
commit 3d8bf78974
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 2 deletions

View file

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

View file

@ -15,7 +15,6 @@ import '@maplibre/maplibre-gl-native';
import advancedPool from 'advanced-pool';
import path from 'path';
import url from 'url';
import util from 'util';
import sharp from 'sharp';
import clone from 'clone';
import Color from 'color';
@ -1458,7 +1457,25 @@ export const serve_rendered = {
}
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
* @param {object} data The background color (or empty string for transparent).

View file

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