TileDataSource: catch unexpected errors (#943)

This commit is contained in:
Emux 2022-08-04 12:52:44 +03:00 committed by GitHub
parent d89a402375
commit e86bf54d8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 46 deletions

View File

@ -1,5 +1,6 @@
/*
* Copyright 2019 Kostas Tzounopoulos
* Copyright 2022 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@ -27,7 +28,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
@ -134,7 +134,8 @@ public class MBTilesMvtTileDataSource extends MBTilesTileDataSource {
responseDataSink.completed(success ? QueryResult.SUCCESS : QueryResult.FAILED);
} else
responseDataSink.completed(QueryResult.TILE_NOT_FOUND);
} catch (IOException e) {
} catch (Throwable t) {
log.error(t.getMessage(), t);
responseDataSink.completed(QueryResult.FAILED);
} finally {
if (cursor != null)

View File

@ -1,6 +1,6 @@
/*
* Copyright 2019 Andrea Antonello
* Copyright 2019 devemux86
* Copyright 2019-2022 devemux86
* Copyright 2019 Kostas Tzounopoulos
*
* This program is free software: you can redistribute it and/or modify it under the
@ -124,8 +124,8 @@ public class MBTilesBitmapTileDataSource extends MBTilesTileDataSource {
Bitmap bitmap = CanvasAdapter.decodeBitmap(new ByteArrayInputStream(bytes));
sink.setTileImage(bitmap);
res = QueryResult.SUCCESS;
} catch (Exception e) {
log.debug("{} invalid bitmap", tile);
} catch (Throwable t) {
log.error(t.getMessage(), t);
} finally {
sink.completed(res);
}

View File

@ -1,5 +1,6 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2022 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -64,8 +65,8 @@ public abstract class TileLoader extends PausableThread implements ITileDataSink
try {
loadTile(mTile);
} catch (Exception e) {
e.printStackTrace();
} catch (Throwable t) {
t.printStackTrace();
completed(FAILED);
}
}

View File

@ -121,9 +121,9 @@ public class VectorTileLoader extends TileLoader implements RenderStyle.Callback
} catch (NullPointerException e) {
log.debug("NPE {} {}", tile, e.getMessage());
e.printStackTrace();
} catch (Exception e) {
log.debug("{} {}", tile, e.getMessage());
e.printStackTrace();
} catch (Throwable t) {
log.debug("{} {}", tile, t.getMessage());
t.printStackTrace();
return false;
}
return true;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2018 devemux86
* Copyright 2018-2022 devemux86
*
* This program is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free Software
@ -15,9 +15,13 @@
package org.oscim.tiling;
import org.oscim.layers.tile.MapTile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class OverzoomTileDataSource implements ITileDataSource {
private static final Logger log = LoggerFactory.getLogger(OverzoomTileDataSource.class);
private final ITileDataSource tileDataSource;
private final int overZoom;
@ -32,14 +36,18 @@ public class OverzoomTileDataSource implements ITileDataSource {
@Override
public void query(MapTile tile, ITileDataSink sink) {
MapTile mapTile = tile;
ITileDataSink dataSink = sink;
int diff = tile.zoomLevel - overZoom;
if (diff > 0) {
mapTile = new MapTile(tile.node, tile.tileX >> diff, tile.tileY >> diff, overZoom);
dataSink = new OverzoomDataSink(sink, mapTile, tile);
try {
MapTile mapTile = tile;
ITileDataSink dataSink = sink;
int diff = tile.zoomLevel - overZoom;
if (diff > 0) {
mapTile = new MapTile(tile.node, tile.tileX >> diff, tile.tileY >> diff, overZoom);
dataSink = new OverzoomDataSink(sink, mapTile, tile);
}
tileDataSource.query(mapTile, dataSink);
} catch (Throwable t) {
log.error(t.getMessage(), t);
}
tileDataSource.query(mapTile, dataSink);
}
@Override

View File

@ -1,6 +1,6 @@
/*
* Copyright 2012 Hannes Janetzek
* Copyright 2017 devemux86
* Copyright 2017-2022 devemux86
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
*
@ -34,12 +34,9 @@ import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import static org.oscim.tiling.QueryResult.DELAYED;
import static org.oscim.tiling.QueryResult.FAILED;
import static org.oscim.tiling.QueryResult.SUCCESS;
public class UrlTileDataSource implements ITileDataSource {
static final Logger log = LoggerFactory.getLogger(UrlTileDataSource.class);
private static final Logger log = LoggerFactory.getLogger(UrlTileDataSource.class);
protected final HttpEngine mConn;
protected final ITileDecoder mTileDecoder;
@ -57,27 +54,27 @@ public class UrlTileDataSource implements ITileDataSource {
public void query(MapTile tile, ITileDataSink sink) {
ITileCache cache = mTileSource.tileCache;
if (mUseCache) {
TileReader c = cache.getTile(tile);
if (c != null) {
InputStream is = c.getInputStream();
try {
if (mTileDecoder.decode(tile, sink, is)) {
sink.completed(SUCCESS);
return;
}
} catch (IOException e) {
log.debug("{} Cache read: {}", tile, e);
} finally {
IOUtils.closeQuietly(is);
}
}
}
QueryResult res = FAILED;
QueryResult res = QueryResult.FAILED;
TileWriter cacheWriter = null;
try {
if (mUseCache) {
TileReader c = cache.getTile(tile);
if (c != null) {
InputStream is = c.getInputStream();
try {
if (mTileDecoder.decode(tile, sink, is)) {
sink.completed(QueryResult.SUCCESS);
return;
}
} catch (IOException e) {
log.debug("{} Cache read: {}", tile, e);
} finally {
IOUtils.closeQuietly(is);
}
}
}
mConn.sendRequest(tile);
InputStream is = mConn.read();
if (mUseCache) {
@ -85,23 +82,25 @@ public class UrlTileDataSource implements ITileDataSource {
mConn.setCache(cacheWriter.getOutputStream());
}
if (mTileDecoder.decode(tile, sink, is))
res = SUCCESS;
res = QueryResult.SUCCESS;
} catch (SocketException e) {
log.debug("{} Socket Error: {}", tile, e.getMessage());
} catch (SocketTimeoutException e) {
log.debug("{} Socket Timeout", tile);
res = DELAYED;
res = QueryResult.DELAYED;
} catch (UnknownHostException e) {
log.debug("{} Unknown host: {}", tile, e.getMessage());
} catch (IOException e) {
log.debug("{} Network Error: {}", tile, e.getMessage());
} catch (Exception e) {
log.debug("{} Error: {}", tile, e.getMessage());
} catch (Throwable t) {
log.error(t.getMessage(), t);
} finally {
boolean ok = (res == SUCCESS);
boolean ok = (res == QueryResult.SUCCESS);
if (!mConn.requestCompleted(ok) && ok)
res = FAILED;
res = QueryResult.FAILED;
if (cacheWriter != null)
cacheWriter.complete(ok);