mmomtchev / node-gdal-async

Node.js bindings for GDAL (Geospatial Data Abstraction Library) with full async support
https://mmomtchev.github.io/node-gdal-async/
Apache License 2.0
124 stars 25 forks source link

openAsync execute interrupt in the mapLimit of async #157

Closed sakitam-fdd closed 1 month ago

sakitam-fdd commented 1 month ago

openAsync execute interrupt in the mapLimit of async,But when the limit is within 10, it seems that it can be executed normally; Not using asynchrony is normal execution

import { openAsync, infoAsync } from 'gdal-async';
import 'ndarray-gdal';
import { mapLimit } from 'async';

async function load(callback) {
  try {
    mapLimit(
      Array.from({ length: 5000 }).map(() => './temp.jpeg'),
      50,
      async function (p) {
        let ds = await openAsync(p);
        // Unable to open file properly
        // The following console code will not execute
        const info = await infoAsync(ds);
        console.log(info);
        ds.close();
      },
      (err, results) => {
        if (err) {
          return callback(err);
        }
        return callback(null, results);
      },
    );
  } catch (e) {
    console.log('limitError', e);
  }
}

load((e, list) => {
  console.log(e, list);
});
mmomtchev commented 1 month ago

It does execute for me - exactly 5000 times. What version of gdal-async are you using and on what platform? What exactly do you see as output?

mmomtchev commented 1 month ago

Also post a gdalinfo of your JPG.

sakitam-fdd commented 1 month ago

System info: Mac mini (2018) macOS Monterey 12.7.5 (21H1222)

Node-version: node v18.16.1 with fnm

gdal-async:3.7.2-1

async:3.2.5

gdalinfo: data.zip

Driver: JPEG/JPEG JFIF
Files: /Users/sakitam-fdd/tiles/2024061200/2024061203/0/0/0/temp.jpeg
       /Users/sakitam-fdd/tiles/2024061200/2024061203/0/0/0/temp.jpeg.aux.xml
Size is 256, 256
Coordinate System is:
PROJCRS["WGS 84 / Pseudo-Mercator",
    BASEGEOGCRS["WGS 84",
        DATUM["World Geodetic System 1984",
            ELLIPSOID["WGS 84",6378137,298.257223563,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4326]],
    CONVERSION["unnamed",
        METHOD["Popular Visualisation Pseudo Mercator",
            ID["EPSG",1024]],
        PARAMETER["Latitude of natural origin",0,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",0,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["False easting",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["easting",east,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["northing",north,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    ID["EPSG",3857]]
Data axis to CRS axis mapping: 1,2
Origin = (-20037508.342789243906736,20037508.342789243906736)
Pixel Size = (156543.033928040968021,-156543.033928040968021)
Metadata:
  EXIF_ImageDescription=-66.69483184814453,37.00061798095703;
  max=37.00061798095703
  min=-66.69483184814453
Image Structure Metadata:
  JPEG_QUALITY=100
Corner Coordinates:
Upper Left  (-20037508.343,20037508.343) (180d 0' 0.00"W, 85d 3' 4.06"N)
Lower Left  (-20037508.343,-20037508.343) (180d 0' 0.00"W, 85d 3' 4.06"S)
Upper Right (20037508.343,20037508.343) (180d 0' 0.00"E, 85d 3' 4.06"N)
Lower Right (20037508.343,-20037508.343) (180d 0' 0.00"E, 85d 3' 4.06"S)
Center      (   0.0000000,   0.0000000) (  0d 0' 0.01"E,  0d 0' 0.01"N)
Band 1 Block=256x1 Type=Byte, ColorInterp=Gray
  Overviews: 128x128
  Image Structure Metadata:
    COMPRESSION=JPEG

Usage: This is for batch processing of map tiles on our side, adding exif information to each tile. The code I gave simplifies some processes. In fact, mapLimit is mainly for concurrent downloads, and additional information is processed after each tile is downloaded.

image

Now the problem is that the gdal processing of each tile is unified into mapLimit, but when the number of concurrent tasks exceeds a certain value, openAsync(p) cannot get dst. In other words, the code is interrupted after executing openAsync, but no error can be caught. It is normal when using synchronous code gdal.open

mmomtchev commented 1 month ago

I tried with your file both on Linux and on macOS with gdal-async 3.7.2 and the file is opened correctly 5000 times.

As you may have seen from my profile, I am currently unemployed because of an extortion with the help of the French police and judicial officials. In order to intimidate me, people are posting simultaneously issues on my projects, with a large number of those coming from China. Yours is simultaneous with a comment by the Github bot in the jest project.

sakitam-fdd commented 1 month ago

I just encountered some problems using this package to process weather-related data. I am sorry if my issue caused some misunderstanding and trouble to you. Currently, the above problems can be bypassed using the synchronization method. This issue will closed first. I hope your situation will get better