Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SIGUP Memory Leak #1455

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/serve_light.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 19 additions & 2 deletions src/serve_rendered.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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).
Expand Down
6 changes: 6 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ async function start(opts) {
app,
server,
startupPromise,
serving,
};
}
/**
Expand Down Expand Up @@ -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;
Expand Down
Loading