Hi @ismcagdas,
I tried this but our customers are still facing this issue. I'm sharing the code and logs in more details.
Code:
protected void Save(XSSFWorkbook excelPackage, FileDto file)
{
Logger.Log(LogSeverity.Info, $"Writing memory stream for file - {file.FileName}, token {file.FileToken}");
using (var stream = new MemoryStream())
{
Logger.Log(LogSeverity.Info, "Writing to memory stream");
excelPackage.Write(stream);
_tempFileCacheManager.SetFile(file.FileToken, stream.ToArray());
Logger.Log(LogSeverity.Info, "Saved to temp file");
}
try
{
var test = _tempFileCacheManager.GetFile(file.FileToken);
Logger.Log(LogSeverity.Info, $"Verified by getting file - {file.FileToken}, bytes - {test.Length}");
}
catch (Exception)
{
Logger.Log(LogSeverity.Error, $"Verification failed for file - {file.FileToken}");
}
}
Logs:
INFO 2020-10-27 12:36:04,170 [36 ] Microsoft.AspNetCore.Hosting.Diagnostics - Request starting HTTP/1.1 GET https://service.primepenguin.com/api/services/app/InventoryReport/GetInventoryListToExcel?Sorting=&MaxResultCount=77&SkipCount=0
INFO 2020-10-27 12:36:04,177 [36 ] pNetCore.Cors.Infrastructure.CorsService - CORS policy execution successful.
INFO 2020-10-27 12:36:04,199 [36 ] uthentication.JwtBearer.JwtBearerHandler - Successfully validated the token.
INFO 2020-10-27 12:36:04,205 [36 ] ft.AspNetCore.Routing.EndpointMiddleware - Executing endpoint 'PrimePenguin.Technology.Reports.Inventory.InventoryReportAppService.GetInventoryListToExcel (PrimePenguin.Technology.Application)'
INFO 2020-10-27 12:36:04,214 [36 ] c.Infrastructure.ControllerActionInvoker - Route matched with {area = "app", action = "GetInventoryListToExcel", controller = "InventoryReport"}. Executing controller action with signature System.Threading.Tasks.Task`1[PrimePenguin.Technology.Dto.FileDto] GetInventoryListToExcel(PrimePenguin.Technology.Reports.Inventory.Dto.GetInventoryListInput) on controller PrimePenguin.Technology.Reports.Inventory.InventoryReportAppService (PrimePenguin.Technology.Application).
INFO 2020-10-27 12:36:04,797 [36 ] Microsoft.AspNetCore.Hosting.Diagnostics - Request starting HTTP/1.1 GET http://service-eu.primepenguin.com/
INFO 2020-10-27 12:36:04,799 [36 ] oft.AspNetCore.Rewrite.RewriteMiddleware - Request redirected to HTTPS
INFO 2020-10-27 12:36:04,800 [36 ] Microsoft.AspNetCore.Hosting.Diagnostics - Request finished in 3.8333ms 301
INFO 2020-10-27 12:36:05,136 [36 ] y.Exporting.InventoryReportExcelExporter - Generating file - InventoryList.xlsx
INFO 2020-10-27 12:36:05,926 [36 ] y.Exporting.InventoryReportExcelExporter - Writing memory stream for file - InventoryList.xlsx, token 151e1d45333744f1a5725739dc01a4cc
INFO 2020-10-27 12:36:05,930 [36 ] y.Exporting.InventoryReportExcelExporter - Writing to memory stream
INFO 2020-10-27 12:36:06,114 [36 ] y.Exporting.InventoryReportExcelExporter - Saved to temp file
INFO 2020-10-27 12:36:06,116 [36 ] y.Exporting.InventoryReportExcelExporter - Verified by getting file - 151e1d45333744f1a5725739dc01a4cc, bytes - 9886
INFO 2020-10-27 12:36:06,136 [36 ] .Mvc.Infrastructure.ObjectResultExecutor - Executing ObjectResult, writing value of type 'Abp.Web.Models.AjaxResponse'.
INFO 2020-10-27 12:36:06,138 [36 ] c.Infrastructure.ControllerActionInvoker - Executed action PrimePenguin.Technology.Reports.Inventory.InventoryReportAppService.GetInventoryListToExcel (PrimePenguin.Technology.Application) in 1923.8685ms
INFO 2020-10-27 12:36:06,139 [36 ] ft.AspNetCore.Routing.EndpointMiddleware - Executed endpoint 'PrimePenguin.Technology.Reports.Inventory.InventoryReportAppService.GetInventoryListToExcel (PrimePenguin.Technology.Application)'
INFO 2020-10-27 12:36:06,140 [36 ] Microsoft.AspNetCore.Hosting.Diagnostics - Request finished in 1970.2227ms 200 application/json; charset=utf-8
INFO 2020-10-27 12:36:25,175 [4 ] Microsoft.AspNetCore.Hosting.Diagnostics - Request starting HTTP/1.1 GET https://primepenguinservice-eu.azurewebsites.net/Ui/Login
Code:
public ActionResult DownloadTempFile(FileDto file)
{
var fileBytes = _tempFileCacheManager.GetFile(file.FileToken);
if (fileBytes == null)
{
AsyncHelper.RunSync(() => _errorReporter.CaptureAsync($"Error in getting file - {file.FileName}, token - {file.FileToken}"));
// Optimistic retry
Thread.Sleep(500);
fileBytes = _tempFileCacheManager.GetFile(file.FileToken);
if (fileBytes == null)
{
return NotFound(L("RequestedFileDoesNotExists"));
}
}
return File(fileBytes, file.FileType, file.FileName);
}
Error:
{"result":"Requested file does not exist!","targetUrl":null,"success":true,"error":null,"unAuthorizedRequest":false,"__abp":true}
I checked redis cache and token was not available.
@maliming, can you please share an example?
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
.
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));
}
Hi @ismcagdas,
Our client reported the same error today. Failed on first try and worked on second. Any idea?
Hi @ismcagdas, U can try setting timeout to 2 minutes.
Hi @ismcagdas,
We switched to Redis cache but still getting the same error.
Hi @zony, How can I increases the expiration timeout?
Hi @ismcagdas, Are you able to reproduce the issue?
Hi @ismcagdas,
I shared the email. You can download the code from my onedrive link: https://1drv.ms/u/s!AlmThg0xqW35grc9Q5nf4Usz4QLU0Q?e=uPiFPH
I'll delete this source code on 15th April.