Open Closed

Problem with ITempFileCacheManager when running more than 1 instance of App #9606


0
ajayak created

.net core/ 9.1.0 / Angular

We are running our App in West Europe and France Central regions on Azure.

In 80% cases, downloading a file with FileDownloadService works perfectly well. In 20% cases, I get the following error in browser with white page:

{"result":"Requested file does not exist!","targetUrl":null,"success":true,"error":null,"unAuthorizedRequest":false,"__abp":true}

12 Answer(s)
  • 0
    zony created
    Support Team

    Hi ajayak, This problem may be caused by cache expiration. After calling ITempFileCacheManager and calling SetFile() method to set temporary files, the effective time of cache is 1 minute. If the front end uses the token to obtain data after more than 1 minute, this exception will be caused.

  • 0
    ajayak created

    Hi @zony, How can I increases the expiration timeout?

  • 0
    ismcagdas created
    Support Team

    Hi @ajayak

    By default, ITempFileCacheManager's default implementation uses in-memory cache. Moving to Redis cache might solve your problem.

  • 0
    ajayak created

    Hi @ismcagdas,

    We switched to Redis cache but still getting the same error.

  • 0
    ismcagdas created
    Support Team

    Hi @ajayak

    Does the request take long time ? Could it timeout on Azure side ? You can also try to increase cache timeout here

  • 0
    ajayak created

    Hi @ismcagdas, U can try setting timeout to 2 minutes.

  • 0
    ajayak created

    Hi @ismcagdas,

    Our client reported the same error today. Failed on first try and worked on second. Any idea?

  • 0
    ismcagdas created
    Support Team

    Hi @ajayak

    1. Can you reproduce this problem yourself ?
    2. Could you explain the use case step by step ? How is the file uploaded etc ...
  • 0
    ajayak created

    Hi @ismcagdas,

    I'm got this problem only once in past 20 days but customer reported it after we switched to Redis cache.

    Backend code:

    public async Task<FileDto> GetReportExcelForDownload(int id)
            {
                var report = await _inventoryReportRepository.GetAsync(id);
                var bytes = await _azureBlobStorageManager.DownloadByteArray(_inventoryReportContainer, report.ExcelFileName);
                var file = new FileDto(report.ExcelFileName, MimeTypeNames.ApplicationVndOpenxmlformatsOfficedocumentSpreadsheetmlSheet);
                _tempFileCacheManager.SetFile(file.FileToken, bytes);
                return file;
            }
    

    Frontend code:

    
    constructor(
            injector: Injector,
            private _inventoryService: InventoryReportServiceProxy,
            private _fileDownloadService: FileDownloadService
        ) {
            super(injector);
        }
        
        
    downloadExcel(id) {
            this._inventoryService.getReportExcelForDownload(id)
                .subscribe(result => this._fileDownloadService.downloadTempFile(result));
        }
    
  • 0
    ismcagdas created
    Support Team

    Hi @ajayak

    Your code seems fine at first look. Do you have the detailed exception message about this problem ? Could it be this line causing the problem ?

    var bytes = await _azureBlobStorageManager.DownloadByteArray(_inventoryReportContainer, report.ExcelFileName);

  • 0
    ajayak created

    Hi @ismcagdas,

    I can't see any error in the logs for the GetReportExcelForDownload function. It must be working fine. If there was an error here, user would be thrown UserFriendlyException.

    The error must be coming from DownloadTempFile .

  • 0
    ismcagdas created
    Support Team

    Hi @ajayak

    Then, it is a bit of a bad approach but;

    1. You can temporarily set the temp file cache duration to 1 day
    2. Log token to log file here https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Core/Controllers/FileController.cs#L31
    3. And next time when a customer faces such a problem, you can check if a file exist in Redis with that token

    It is hard to find a solution if we can't reproduce the problem on our side.