ThinkGeo.com    |     Documentation    |     Premium Support

HttpRequestException is thrown without network connection

With following test code and ThinkGeo version 14.2.1:

private async void mapView_Loaded(object sender, RoutedEventArgs e)
{
    var mapView = sender as MapView;
	// Set the Map's Unit to Meter.
    mapView.MapUnit = GeographyUnit.Meter;
    // Set the Current Extent to the Max Extent of ThinkGeo Map.
    mapView.CurrentExtent = MaxExtents.ThinkGeoMaps;
                            
    // Add a base map overlay.
    var baseOverlay = new ThinkGeoCloudRasterMapsOverlay("AOf22-EmFgIEeK4qkdx5HhwbkBjiRCmIDbIYuP8jWbc~", 
    "xK0pbuywjaZx4sqauaga8DMlzZprz0qQSjLTow90EhBx5D8gFd2krw~~", ThinkGeoCloudRasterMapsMapType.Light_V1_X1);

    // Set up the tile cache for the base overlay, passing in the location and an ID to distinguish the cache.     
    baseOverlay.TileCache = new FileRasterTileCache(@".\cache", "basemap");
    **baseOverlay.DrawingExceptionMode = DrawingExceptionMode.DrawException;**
    // Add the newly created overlay to mapView.
    mapView.Overlays.Add(baseOverlay);
                            
    // Refresh the Map
    await mapView.RefreshAsync();
}

If network connection is disconnected after application start-up it crashes with HttpRequestException after around one hour with following stack trace:

[Exception] System.Net.Http.dll!System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(string host, int port, System.Net.Http.HttpRequestMessage initialRequest, bool async, System.Threading.CancellationToken cancellationToken) (Unknown Source:0)
[Exception] System.Net.Http.dll!System.Net.Http.HttpConnectionPool.ConnectAsync(System.Net.Http.HttpRequestMessage request, bool async, System.Threading.CancellationToken cancellationToken) (Unknown Source:0)
[Exception] System.Net.Http.dll!System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(System.Net.Http.HttpRequestMessage request, bool async, System.Threading.CancellationToken cancellationToken) (Unknown Source:0)
[Exception] System.Net.Http.dll!System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(System.Net.Http.HttpConnectionPool.RequestQueue<System.Net.Http.HttpConnection>.QueueItem queueItem) (Unknown Source:0)
[Exception] System.Net.Http.dll!System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(System.Net.Http.HttpRequestMessage request, bool async, bool doRequestAuth, System.Threading.CancellationToken cancellationToken) (Unknown Source:0)
[Exception] System.Net.Http.dll!System.Net.Http.RedirectHandler.SendAsync(System.Net.Http.HttpRequestMessage request, bool async, System.Threading.CancellationToken cancellationToken) (Unknown Source:0)
[Exception] System.Net.Http.dll!System.Net.Http.HttpClient.SendAsync.__Core|83_0(System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationTokenSource cts, bool disposeCts, System.Threading.CancellationTokenSource pendingRequestsCts, System.Threading.CancellationToken originalCancellationToken) (Unknown Source:0)
[Exception] ThinkGeo.Core.dll!GRU=.8h0=.KT8=.MoveNext() (Unknown Source:0)
[Exception] ThinkGeo.Core.dll!GRU=.8h0=.Lj8=.MoveNext() (Unknown Source:0)
System.Private.CoreLib.dll!System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.Tasks.Task.ThrowAsync.AnonymousMethod__128_1(object state) (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.QueueUserWorkItemCallback.Execute() (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() (Unknown Source:0)
System.Private.CoreLib.dll!System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() (Unknown Source:0)

To me it seems that something is updated inside ThinkGeo after one hour and without network connection exception is thrown. Could you please help to investigate is there some possibility to prevent this crash ?

I did attach de-compiled ThinkGeo file throwing the exception. (it’s thrown from line 207 and was called from line 269)

BR, SimoThrowingClass.cs (5.6 KB)

HI Simo,

This issue is recreated and fixed in the latest beta033. Please pull the latest and have a try.

Thanks,
Ben

Hi,

Yes, it seems that with beta033 exception is not thrown anymore. But after connections is restored map loading fails with exception “The HTTP request failed with status code: Unauthorized”

So I guess issue happens when authentication token was attempted to update without connection ? But is not now so that when token update is not done it causes this “Unauthorized” problem ?

Is it now so that exception is not thrown in any case if update fails (I have seen also exception with reason " Fetching Token Failed with Status Code: InternalServerError" coming from line 216) ?

BR, Simo

Hi Simo,

Your guesses are all correct. It’s because the Token failed to be updated when internet was down and cannot be properly updated after the internet is restored.

Please pull the latest beta034 which can successfully re-fetch the token after the network is back on. We eat the internal exceptions within GetTokenAsync() but you can log the errors to Output Window (they can also be logged to other places by setting some properties in ThinkGeoDebugger) if you do the following in the code

ThinkGeoDebugger.LogType = ThinkGeoLogType.WebRequest;
ThinkGeoDebugger.LogLevel = ThinkGeoLogLevel.All;

Let me know if you still see any issues.

Thanks,
Ben

Hi,

With latest beta it seems that first attempt to download map after connection is restored fails with “Unauthorized” reason. Second attempt is then successful. So it works better but would be better to improve token refresh that there would not be that first failed attempt (maybe you could refresh expired token before attempting to download map) ? That first failed attempt would cause application to crash if exceptions are not drawn and does not look good even if those are drawn to map.

Just to be sure about GetTokenAsync() exception handling is it now so that also those cases where server responds with non-successful response are internally handled and not throwing an error ?

BR, Simo

Hi Simo,

I couldn’t exactly recreate the issue, but I do see we still sent the request even the Token is invalid, which I think relates to this issue. This has been fixed in beta037, pull the latest and have another try.

Thanks,
Ben

Hi,

Yes, with latest beta first request(s) after connection is restored are not sent with invalid token anymore. So now recovery from connection break works as expected.

Could you please also confirm that those non-successful server responses are internally handled and not throwing exception anymore in GetTokenAsync() ?

Do you have any estimation when these fixes would be released ?

Br, Simo

Hi Simo,

Yep, non-successful server responses are internally handled and GetTokenAsync() will never throw an exception.

There will be a new release around the new year.

Thanks,
Ben