titanium-web-proxy icon indicating copy to clipboard operation
titanium-web-proxy copied to clipboard

Race condition on HttpStream

Open valutcizen opened this issue 5 years ago • 4 comments

Sometimes working with Open Streets Maps (OSM) on specific time (starts about 15:00 UTC+2) there is response that cause bufferLength is less than 0! Everywhere in source it is impossible until it is race condition.

My app: proxy that fixes OSM issue with endless connection. I wait for body 30 seconds and if this is not appears I ask few times again by HttpClient.

private

AtChangedPlace

bytesRead <= 0 is changed by me to prevent endless loop.

valutcizen avatar Sep 01 '20 13:09 valutcizen

Could you please create a small test app to reproduce the issue? Parallel read shoudl not happen here, so no race condition..unless you are doing something strange.

honfika avatar Sep 26 '20 16:09 honfika

The problem with small test app is that there is no problems with open street maps since 18th September, and this issue I have only on these servers, so now it is not possible to reproduce this issue.

valutcizen avatar Sep 28 '20 15:09 valutcizen

But what did you wrote to the TWP event handler? It should not be called parallel.

honfika avatar Sep 28 '20 18:09 honfika

private async Task Proxy_BeforeResponse(object sender, SessionEventArgs e)
{
    try
    {
        if (e.Exception != null || e.HttpClient.Response.StatusCode != 200)
        {
            await TryRetringAsync(e);
        }
        else
        {
            Task bodyTask = e.GetResponseBody();

            if (!bodyTask.Wait(timeout))
                await TryRetringAsync(e);
        }
    }
    catch (Exception ex)
    {
        LogToFile(ex.ToString());
    }
}

Where TryRetryingAsync is method that download body by HttpClient and changes response to new body.

valutcizen avatar Sep 29 '20 05:09 valutcizen