2

I have an async controller that returns results from a collection.

Sometimes, I will get an intermittent error if I click around the page to fast.

The errors are (in the browser console):

Failed to load resource: net::ERR_HTTP2_PROTOCOL_ERROR

Or it will return this error from the front-end:

500 : Ajax request has failed 

I have tried debugging locally in Visual Studio and stepping through the code, but locally, I don't get any errors and I can't figure out why it's doing it.

I have added a line that checks to make sure the returned collection is not null, so it's not that.

Here is the controller:

[HttpGet("factapi/Factory/{factoryId}/engines")]
public async Task<IActionResult> Get(Int32 factoryId)
{
    using (var tran = Session.BeginTransaction())
    {
        var engineId = page.Assembly.Id.TrimToNull();
        if (engineId == null) return NoContent();
        var engines = await GetEngines(new Guid(engineId));
        if (engines == null)
        {
            return BadRequest();
        }
        return Ok(engines);
    }
}

This is the async method that gets the engines:

    public async Task<IEnumerable<Engine>> GetEngines(Guid id)
    {
        var engines = new List<Engine>();

        engines = await GetEngineList<Engine>(id);

        return engines.Where(t => start.LiesBetween(t.BuildTime.AddMinutes( - 7), t.BuildTime.AddMinutes((t.TimeBreak / 60) + 7)));

    }

And here is GetEngineList:

public async Task<List<T>> GetEngineList<T>(Guid id)
{
    List<T> collectionVal = default(List<T>);

    var factoryResponse = await GetList(id);
    var fullList = factoryResponse.Results;
    var settings = new JsonSerializerSettings
        {
            NullValueHandling = NullValueHandling.Ignore,
            MissingMemberHandling = MissingMemberHandling.Ignore
        };
        
    var json = JsonConvert.SerializeObject(fullList);

    var final = JsonConvert.DeserializeObject<List<T>>(json, settings);
    collectionVal = final;
    return collectionVal;
}

Another set of eyes would be welcome! :)

Tiny Wang
  • 10,423
  • 1
  • 11
  • 29
SkyeBoniwell
  • 6,345
  • 12
  • 81
  • 185
  • See if [this](https://stackoverflow.com/questions/58215104/whats-the-neterr-http2-protocol-error-about) post can help you – GuyKorol Aug 26 '21 at 13:35
  • @GuyKorol thanks but I couldn't find anything in my code or setup that hinted at any of those answers. – SkyeBoniwell Aug 26 '21 at 15:41
  • Which webserver you use? And can Iunderstand that the local vs2019 is running normally, and there will be errors after deployment. right? – Jason Pan Aug 27 '21 at 02:12
  • @JasonPan I m using IIS on Windows Server 2016. Local is fine, but I run into intermittent errors on the IIS server. – SkyeBoniwell Aug 27 '21 at 14:03
  • @SkyeBoniwell Hi, I'm afraid there's some configuration we missed led this issue as you said it's all right in local. So you could you pls offer your iis version and maybe some error code not limited to 500. As I found some cases which is similar such as [this one](https://forums.iis.net/t/1214731.aspx). I mean we may change a way to troubleshot it. – Tiny Wang Aug 31 '21 at 02:01
  • What is `page.Assembly.Id` and why is factoryId never used? – H H Aug 31 '21 at 09:48
  • 1
    Is KB5004476 on your server? Please check [this link](https://stackoverflow.com/questions/67911570/failed-to-load-resource-neterr-http2-protocol-error-for-react-app-after-upg) to see if it helps. – Fei Xue Sep 07 '21 at 02:16

0 Answers0