Base solution for your next web application
Open Closed

Application service or web api timeout #1323


User avatar
0
diego created

Hi all, i need help about strange timeout error, below details:

1 - I have a application service with a long running method that execute a massive import

[AbpAuthorize(AppPermissions.Pages_Projects_AllProjects)]
        [UnitOfWork(IsDisabled = true)]
        public virtual async Task<DataImporterListResultDto<ProjectImportDto>> ImportProjects(FileDto fileDto)
        {
			....
			....
			....

			// Start saving element to database
			foreach (ProjectImportDto item in dto.ImportedList.Where(i => i.IsValid))
			{
				try
				{
					using (var unitOfWork = _unitOfWorkManager.Begin(new UnitOfWorkOptions
					{
						IsolationLevel = IsolationLevel.ReadCommitted,
						IsTransactional = true,
						Timeout = TimeSpan.FromMinutes(30)
					}))
					{
						bool saved = await saveProject(dto, item, excludeAttachments);
						if (!saved)
						{
							dto.AddWarningMessage(String.Format(L("ImportSaveProjectFailed"), item.LegacyId));
							Logger.Warn(string.Format(L("ImportSaveProjectFailed"), item.LegacyId));
							throw new Exception(String.Format(L("ImportSaveProjectFailed"), item.LegacyId));
						}
						else
						{
							unitOfWork.Complete();
							dto.TotalImportedRecords++;
						}
					}

				}
				catch (Exception ex)
				{
					Logger.Error(ex.Message);
				}
			
			....
			....
        }

As you can see the UnitOfWork is created with 30 minutes timeout

2 - I use DynamicWebApi in standard mode to expose the application service

//Automatically creates Web API controllers for all application services of the application
            DynamicApiControllerBuilder
                .ForAll<IApplicationService>(typeof(ImproveApplicationModule).Assembly, "app")
                .Build();

3 - My site is AngularJs SPA website, ORM is EntityFramewrok and the database server is SQL Server 2012

4 - Client side the application service is called in that way:

projectService.importProjects({
			fileName: vm.fileToImport.fileName,
			fileType: vm.fileToImport.fileType,
			fileToken: vm.fileToImport.fileToken,
		}, { timeout: 600000 }).success(function (result) {
			vm.importResult = result;
		}).error(function () {
			abp.notify.error(app.localize('WronglyImported'));
		}).finally(function () {
			vm.loading = false;
		});

Note the extra-timeout on ajax call


The problem: All work fine in dev-env with visual studio, fails sistematically on Azure after 4 minutes execution The returned error is: "500 - The request timed out. The web server failed to respond within the specified time"

I have tried to set timeout on web.config in the "httpruntime" section and also in the "system.webservice/security" section whithout success. I also tried to update Abp.* packages to latest version but without improvements. With DynamicWebApi i can't decorate method with specific timeout attribute, any suggestions to resolve the issue?

Thanks in advance, Diego


2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I think it is more related to azure settings. I couldn't find a clear solution but every topic on the internet refers to this post <a class="postlink" href="https://azure.microsoft.com/en-us/blog/new-configurable-idle-timeout-for-azure-load-balancer/">https://azure.microsoft.com/en-us/blog/ ... -balancer/</a>.

    As far as I understand, long running web requests are not good for Azure. You might consider doing this in a background job if it satisfies your needs.

  • User Avatar
    0
    diego created

    Hi ismcagdas, i think you are right

    Unfortunatly i use web app on Azure and seems which is not possible to set timeout on load balancer (default 4 minute). I don't agree and understand this restriction, the only way for me is to change approach.

    Thank you for suggestion, really useful