fix memory leak on SIGHUP
This commit is contained in:
parent
1d60dd6afc
commit
a245126c20
3 changed files with 26 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue