How to safely abort a piped stream in NodeJS?
Asked Answered
R

0

7

I'm using Requests to pipe an HTTP Stream to a local geospatial file-processing utility, ogr2ogr:

    httpStream.on('response', function(response) {
        var ogr = ogr2ogr(response)
                .skipfailures()
                .options(['-t_srs', 'EPSG:4326']);

However, if the file I receive is too big I want to abort:

        response.on('data', function (chunk) {
            len += chunk.length;
            if (!abort && len > convert.maxConversionSize) {
                tooBigError(request, res);
                abort = true;
                httpStream.abort();
                // response.destroy(); //??
            }

Is calling httpStream.abort() enough? What exactly happens to the ogr2ogr process? Is it left hanging? What is the correct way to ensure it gets cleaned up and isn't left with a half-filled memory buffer somewhere?

Rasmussen answered 4/7, 2016 at 2:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.