Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have created a React Project using dotnetcore 3.1 Version. This is hosted on an IIS Server on AWS Lightsail . We use AWS Lightsail Loadbalancers . The Web Service communicates to an Microsoft SQL Server Express (64-bit) Database , version 14.0.3281.6 using Entity Framework Core.

The problem we are facing is:

We make a call to the webservice via a POST request. This runs a query on the database. This query fetches data from many related tables using Include()

For large data we have noticed that the web service return a 504 Gateway Timeout .

We have tried setting the CommandTimeout to 900 seconds as below

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            if (!optionsBuilder.IsConfigured)
                IConfigurationRoot configuration = new ConfigurationBuilder()
                   .SetBasePath(Directory.GetCurrentDirectory())
                   .AddJsonFile("appsettings.json")
                   .Build();
                var connectionString = configuration.GetConnectionString("DefaultConnection");
                optionsBuilder.UseSqlServer(connectionString, sqlServerOptions => sqlServerOptions.CommandTimeout(900));

Our Connection string

"DefaultConnection": "Data Source=server_name_here,port_number_here;Initial Catalog=db_name_here;Integrated Security=False;Persist Security Info=False;User ID=user_name_here;Password=password_here

Other things we have tried: Setting the requestTimeout="00:20:00" in the web.config

Application Pool settings screenshot

Are we missing something?

I suspect that this has something to do with the AWS loadbalancer configuration. The 504 Gateway timeout probably comes from the loadbalancer because it expects your application to answer within a certain amount of time (which it doesn't for large data).

You could try to (temporarily) disable the loadbalancer and see if you still hit the 504 Gateway Timeout error.

You could also add a new controller to test this issue:

[ApiController]
[Route("[controller]")]
public class TimeoutController : ControllerBase
    [HttpGet]
    public IActionResult Get(int timeoutInSeconds)
        Thread.Sleep(TimeSpan.FromSeconds(timeoutInSeconds));
        return Ok($"Waited for {timeoutInSeconds} seconds.");

Then you can call it with your browser on http://[server:port]/timeout?timeoutInSeconds=10

You can then gradually increase the timeout. This helps you to identify the threshold and to prove that it does not have something to do with your application code (because the controller does not do anything but wait).

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.