getZxy never resolving the returned promise, program stalled (using pmtiles js module) #587
-
|
hello, im currently using pmtiles to read a file from my local disk, using my own Source class like this `class FileSource { async initialize(filename) { getKey() { async getBytes(offset, length) { close() { export const transformPMTiles = async (sourceFilePath, destinationFilePath, minZoom, maxZoom, onFeatures, onProgress, topLeft, bottomRight) => { .... sadly, every once in a while the program just stalls, when loading tiles from the pmtiles file i found here:https://maps.protomaps.com/builds/ no exception raised, nothing, i just keep awaiting for ever, surprisingly (for js code) it doesn't happen at the same moment im reading all tiles, from z 0 to z 15, it usually happens at z 11, BUT at a random x and y, those tiles certainly exist, im only ever fetching tiles with a valid z,x,y so, is there native C code involved here ? as the whole process takes a LOT of time (the stall can happen at anytime, sometimes hours after i start the script) i had to use the following technique: i run he code from the (mac) terminal, with --inspect, then, when i see there is no longer any movement i attach the debugger during the execution of the code i leave "breadcrumbs" in global variables that i can access despite not being in scope, thats how i know that the lest line of code executed in my script is before going into getZxy im currently running the code, the next time it stalls, i will be able to call getZxy again, with the same parameters and step the code, to see if it fails again (i expect not, as this must be some race/timing condition) |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
|
chatgpt, of all "people" recommends this work around, lets see :) import { PMTiles, ResolvedValueCache } from 'pmtiles' // 1. Create a "file://" Source (so PMTiles uses local disk I/O) // 2. Make a cache that never shares promises and doesn’t pre-fetch // 3. Hand that cache to PMTiles |
Beta Was this translation helpful? Give feedback.
-
|
damn no, that didn't fix it :( |
Beta Was this translation helpful? Give feedback.
-
|
oh well, after a few more hours of debugging i think the problem might be with node's event loop hanging, it's not getZxy that hangs by itself, but when it calls getBytes my call to fd.read(buffer, 0, length, offset) hangs i have no idea why, i'm trying with sync IO now, my code isn't doing anything concurrently, so it should just work |
Beta Was this translation helpful? Give feedback.
-
|
in the end it turned out to be a bug in the cli-progress module that was calling setTimeout waay too often, sorry :) |
Beta Was this translation helpful? Give feedback.
chatgpt, of all "people" recommends this work around, lets see :)
import { PMTiles, ResolvedValueCache } from 'pmtiles'
// 1. Create a "file://" Source (so PMTiles uses local disk I/O)
const source = await new FileSource(path)) (see above)
// 2. Make a cache that never shares promises and doesn’t pre-fetch
// - maxCacheEntries = 0 (no entries retained)
// - prefetch = false
const cache = new ResolvedValueCache(0, false)
// 3. Hand that cache to PMTiles
const pm = new PMTiles(source, cache)