You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am developing a simple script to prefetch all tiles from a map server. However, it still has no proper timeout to wait for the tile to render, and it starts to fetch many tiles at once. Until bun crashes. My current vscode launch script and code:
import{Command}from"commander";importpathfrom"path";import{mkdir,writeFile}from"fs/promises";interfaceTile{z: number;x: number;y: number;}interfaceBBox{minLon: number;maxLon: number;minLat: number;maxLat: number;}// Convert latitude/longitude to tile coordinatesfunctionlatLonToTile(lat: number,lon: number,zoom: number): {x: number;y: number}{constlatRad=(lat*Math.PI)/180;constn=Math.pow(2,zoom);constx=Math.floor(((lon+180)/360)*n);consty=Math.floor(((1-Math.log(Math.tan(latRad)+1/Math.cos(latRad))/Math.PI)/2)*n);return{ x, y };}// Generate tiles within bounding box for a specific zoom levelfunction*generateTilesForZoom(bbox: BBox,zoom: number): Generator<Tile>{constminTile=latLonToTile(bbox.minLat,bbox.minLon,zoom);constmaxTile=latLonToTile(bbox.maxLat,bbox.maxLon,zoom);// Ensure correct order of min/maxconstminX=Math.min(minTile.x,maxTile.x);constmaxX=Math.max(minTile.x,maxTile.x);constminY=Math.min(minTile.y,maxTile.y);constmaxY=Math.max(minTile.y,maxTile.y);for(letx=minX;x<=maxX;x++){for(lety=minY;y<=maxY;y++){yield{z: zoom, x, y };}}}// Read stream to Uint8ArrayasyncfunctionreadStream(reader: ReadableStreamDefaultReader): Promise<Uint8Array>{constchunks: Uint8Array[]=[];lettotalSize=0;while(true){const{ done, value }=awaitreader.read();if(done)break;chunks.push(value);totalSize+=value.length;}constresult=newUint8Array(totalSize);letoffset=0;for(constchunkofchunks){result.set(chunk,offset);offset+=chunk.length;}returnresult;}// Fetch and optionally save tile dataasyncfunctionfetchTileData(tile: Tile,serverUrl: string,outputDir?: string){consturl=newURL(`/tiles/${tile.z}/${tile.x}/${tile.y}.pbf`,serverUrl);try{console.log(`Fetching tile ${tile.z}/${tile.x}/${tile.y}`);constresponse=awaitfetch(url.toString());if(!response.ok){thrownewError(`HTTP ${response.status}: ${response.statusText}`);}if(outputDir&&response.body){constreader=response.body.getReader();constcontent=awaitreadStream(reader);constfilename=path.join(outputDir,`${tile.z}`,`${tile.x}`,`${tile.y}.pbf`);awaitmkdir(path.dirname(filename),{recursive: true});awaitwriteFile(filename,content);console.log(`Saved ${filename}`);}}catch(_error){console.error(`Error processing tile ${tile.z}/${tile.x}/${tile.y}:`// error);}}asyncfunctionmain(){constprogram=newCommand();program.name("tile-generator").description("Pre-render vector tiles for a map server within specified bounding box").argument("<server>","Server URL (e.g., http://localhost:8080)").argument("<minLon>","Minimum longitude",parseFloat).argument("<maxLon>","Maximum longitude",parseFloat).argument("<minLat>","Minimum latitude",parseFloat).argument("<maxLat>","Maximum latitude",parseFloat).option("-m, --min-zoom <number>","Minimum zoom level","8").option("-z, --max-zoom <number>","Maximum zoom level","18").option("-o, --output <dir>","Output directory for cached tiles").option("-c, --concurrency <number>","Number of concurrent requests","5");program.parse();constoptions=program.opts();const[server,minLon,maxLon,minLat,maxLat]=program.args;constminZoom=parseInt(options.minZoom);constmaxZoom=parseInt(options.maxZoom);if(maxZoom<minZoom){console.error("Error: Maximum zoom level must be greater than the minimum zoom level.");process.exit(1);}constconcurrency=parseInt(options.concurrency);// Example bounds for The Netherlandsconstbbox={minLon: +minLon||3.3,// Western pointmaxLon: +maxLon||7.2,// Eastern pointminLat: +minLat||50.7,// Southern pointmaxLat: +maxLat||53.6,// Northern point};console.log("Starting tile generation with parameters:");console.log(`Server: ${server}`);console.log(`Bounding box: ${JSON.stringify(bbox)}`);console.log(`Min zoom: ${minZoom}`);console.log(`Max zoom: ${maxZoom}`);console.log(`Output directory: ${options.output||"None (preview mode)"}`);console.log(`Concurrency: ${concurrency}`);// Generate and process tiles for each zoom levelfor(letzoom=minZoom;zoom<=maxZoom;zoom++){consttiles=Array.from(generateTilesForZoom(bbox,zoom));console.log(`Processing zoom level ${zoom} (${tiles.length} tiles)`);// Process tiles with concurrency limitfor(leti=0;i<tiles.length;i+=concurrency){constbatch=tiles.slice(i,i+concurrency);awaitPromise.all(batch.map((tile)=>fetchTileData(tile,server,options.output)));}}console.log("Tile generation completed!");}if(import.meta.main){main().catch((error)=>{console.error("Fatal error:",error);process.exit(1);});}
Relevant log output
Fetching tile 13/4258/2675
Fetching tile 13/4258/2676
============================================================
Bun v1.1.42 (50eec002) Linux x64
WSL Kernel v5.15.153 | glibc v2.35
CPU: sse42 popcnt avx avx2
Args: "bun""/home/erik/dev/zodk/prerender/src/index.mts""https://sr-data.hex.tno.nl/geoserver226/gwc/service/tms/1.0.0/tno-dbe:zodk_gemeente_vestigingen@EPSG:3857@pbf""3.3""7.2""50.7""53.6""-z 18""-o ./cache""-c 5"
Features: fetch(12890) http_server jsc transpiler_cache tsconfig
Builtins: "bun:main""node:child_process""node:events""node:fs""node:fs/promises""node:path""node:process""node:string_decoder""node:util/types"
Elapsed: 61489ms | User: 5300ms | Sys: 9447ms
RSS: 1.07GB | Peak: 0.21GB | Commit: 1.07GB | Faults: 49
panic: Illegal instruction at address 0x59D8406
oh no: Bun has crashed. This indicates a bug in Bun, not your code.
Stack Trace (bun.report)
Bun v1.1.42 (50eec00) on linux x86_64 [AutoCommand]
How can we reproduce the crash?
I am developing a simple script to prefetch all tiles from a map server. However, it still has no proper timeout to wait for the tile to render, and it starts to fetch many tiles at once. Until bun crashes. My current vscode launch script and code:
Relevant log output
Stack Trace (bun.report)
Bun v1.1.42 (
50eec00
) on linux x86_64 [AutoCommand]Illegal instruction at address 0x059D8406
??
ld-temp.o:0
:bmalloc_heap_config_specialized_try_deallocate_not_small_exclusive_segregated
ld-temp.o:0
:void JSC::MarkedBlock::Handle::specializedSweep<true, (...)1, (...)1, (...)1, (...)0, (...)1, (...)1, JSC::IsoInlinedHeapCellType<JSC::JSString>::DestroyFunc>
ld-temp.o:0
:JSC::MarkedBlock::Handle::sweep
ld-temp.o:0
:JSC::LocalAllocator::tryAllocateIn
ld-temp.o:0
:JSC::LocalAllocator::allocateSlowCase
LocalAllocatorInlines.h:41
:JSC::JSString::create
JSString.h:963
:WTF::Detail::CallableWrapper<Bun::BunInspectorConnection::sendMessageToDebuggerThread(...)::'lambda'(...), void, WebCore::ScriptExecutionContext&>::call
Function.h:82
:Bun__performTask
event_loop.zig:300
:src.bun.js.event_loop.EventLoop.tickQueueWithCount__anon_147067
Features: fetch, http_server, jsc, transpiler_cache, tsconfig, tsconfig
The text was updated successfully, but these errors were encountered: