Skip to content

MapiResponse never gets garbage collected in Node #396

Description

@markgandy

We have a memory leak issue with a Node app that appears to be caused by MapiResponse never getting cleaned up by the garbage collecter. We are creating a client and using to get directions as below using Node v12.16:

const mapboxDirectionsFactory = require('@mapbox/mapbox-sdk/services/directions');

class MapboxAdapter {
	constructor(options) {
		this.client = mapboxDirectionsFactory(options);
	}
	directionsConsideringTraffic({geoLocations}) {
		return this.client.getDirections({
			profile: 'driving-traffic',
			geometries: 'geojson',
			steps: true,
			waypoints: geoLocations.map(coordinates => ({coordinates}))
		}).send();
	}
}

module.exports = {
	MapboxAdapter
};

But we can see that MapiRequest and MapiResponse never get cleaned up. Looking at heap snapshots from prod we can see these just keep growing (example here has grown up to 90MB just for MapiResponse)
image

I have also reproduced running locally in the Chrome debugger. I can see these objects build up and never get removed even when I manually run a GC in Chrome.

It looks like the SDK uses the global namespace so I guess this is why they are never GC'd? Is there something special we should be doing in Node to avoid this issue?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions