I'm getting an error similar to #861. It doesn't fire on every tile, but occasionally on particular tiles.
I'm serving data rendered with mapnik through tilelive-bridge, so pbf tiles are by the spec I guess.
Does this error fire when reading source attribute fields or geometry also?
Data-wise, I've got a single layer with valid polygon geometry and just two fields (integer and string) served from postgis.
Any clues why this happens?
@mofoyoda the error generally fires when it sees something it doesn't expect when decoding tiles from protocol buffers. Can you send us a sample of a particular tile that doesn't work?
@mourner yep, I've put some tiles to a gist here
I've also tested on different browsers and found out Safari and FF throw this error more frequently than Chrome. But the error always points to Pbf.ReadFields and Pbf.skip.
I've been digging into tilelive output to check if it's Pbf decoder error or not, and I've figured out this:
When I just serve tiles from tilelive output like:
tileSource.getTile(z, x, y, function(err, tile, headers) {
res.set(headers);
res.send(tile);
}
There are no errors when decoding it, but when I serve the same tile from the filesystem:
tileSource.getTile(z, x, y, function(err, tile, headers) {
fs.writeFile(config.tilePath + '/' + z + '/' + x + '/' + y + '.pbf', tile, {encoding: 'base64'}, function (err) {
rtile = readFileSync(config.tilePath + '/' + z + '/' + x + '/' + y + '.pbf', {encoding: 'base64'});
res.set(headers);
res.send(tile);
});
});
I get Uncaught Error: Unimplemented type: 3
How can a tile buffer be corrupted when writing it out and reading back from fs? Maybe I've messed up encoding or smth?
Are you serving it gzipped and with Content-Encoding: gzip (so that the browser decodes it), but saving it gzipped and not decoding it when served from filesystem?
Thanks, @jfirebaugh I got it running now. I'm serving with Content-Encoding: gzip both from tilelive output and filesystem. When I changed readFile and res.send to just res.sendFile it started working as expected. Sorry, guys, I guess Pbf decoding works fine. I'll check out some more and confirm that here.
But I still don't get how writeFile + readFile change the content of the tile. Maybe the content should be cast to buffer after being read?
But I still don't get how writeFile + readFile change the content of the tile.
It doesn't. The issue was likely that you were serving gzipped files sometimes with Content-Encoding: gzip and sometimes not. mapbox-gl-js always expects non-gzipped PBFs, i.e. if they are served gzipped they need to have Content-Encoding: gzip so that the browser performs decoding.
Hey a note on this having hit the same problem myself: the vector tile API https://tiles.mapbox.com/v4/ currently seems to ignore any 'Accept-Encoding' header and returns tiles encoded as gzip regardless.
Hello, how should I use Content-Encoding: gzip?
Most helpful comment
It doesn't. The issue was likely that you were serving gzipped files sometimes with
Content-Encoding: gzipand sometimes not. mapbox-gl-js always expects non-gzipped PBFs, i.e. if they are served gzipped they need to haveContent-Encoding: gzipso that the browser performs decoding.