yocontra / node-gdal-next

Node.js bindings for GDAL (Geospatial Data Abstraction Library) [Fork]
https://contra.io/node-gdal-next/
Apache License 2.0
75 stars 35 forks source link

Closing the dataset while an async operation is running can end with a segfault #38

Open mmomtchev opened 3 years ago

mmomtchev commented 3 years ago
const gdal = require('gdal-next');
const ds = gdal.open('sample.tif');
const band = ds.bands.get(1)
band.pixels.readAsync(0, 0, 10, 10);
ds.close();

This is not expected to work, but the user should be protected against a segfault.

yocontra commented 3 years ago

@mmomtchev I think the correct behavior would be for ds.close() to throw if work is still ongoing, thoughts?

mmomtchev commented 3 years ago

In the next version ds.close() will block until the currently running I/O finishes (it cannot be canceled) and then it will cancel all operations that have not yet started - they will end up rejecting with Dataset closed Frankly, if I had seen this sooner, I would have probably settled for it 😄 But I already implemented a locking hierarchy on top of Brian Revis excellent PtrManager which manages the lifetime of all datasets