PainlessHttp icon indicating copy to clipboard operation
PainlessHttp copied to clipboard

Singleton causing problems

Open tjoskar opened this issue 9 years ago • 0 comments

Hi,

First of all, awesome project!

However, it seems to be a problem when the same instance of PainlessHttp is handling multiple request at the same time (thread-unsafe?).

I have the following code in a ApiController-class:

[Route("api/test")]
[HttpGet]
public async Task<IHttpActionResult> Test(string id = "0")
{
    var response = await httpSingleton.GetAsync<string>(string.Format("/echo/{0}", id)); // Replies with `id`
    return Ok(response.Body);
}

and if I make a several requests at the same time against the endpoint above (api/test/?id={id}) I can get the response all mixed up. Eg. GET api/test/1 can reply "2" (expected 1) and GET api/test/2 can reply "1" (expected 2).

Take a look at my gist to get a full example: https://gist.github.com/tjoskar/c1f65bed89d67a503728

Keep up the good work!

tjoskar avatar Oct 21 '15 16:10 tjoskar