eShop icon indicating copy to clipboard operation
eShop copied to clipboard

catalog-api crashing after receiving request from webapp

Open vhvb1989 opened this issue 1 year ago • 3 comments

After deploying eshop to Azure, the catalog-api crashes when it gets the first request from webapp, the logstream is:

2024-02-05T23:58:21.041277739Z       SELECT c."Id", c."AvailableStock", c."CatalogBrandId", c."CatalogTypeId", c."Description", c."Embedding", c."MaxStockThreshold", c."Name", c."OnReorder", c."PictureFileName", c."Price", c."RestockThreshold"
2024-02-05T23:58:21.041285032Z       FROM "Catalog" AS c
2024-02-05T23:58:21.041290372Z       ORDER BY c."Name"
2024-02-05T23:58:21.041305490Z       LIMIT @__p_1 OFFSET @__p_0
2024-02-05T23:58:21.042802853Z fail: Microsoft.AspNetCore.Server.Kestrel[13]
2024-02-05T23:58:21.042817751Z       Connection id "0HN16KMJOLU5V", Request id "0HN16KMJOLU5V:00000004": An unhandled exception was thrown by the application.
2024-02-05T23:58:21.042825235Z       System.NullReferenceException: Object reference not set to an instance of an object.
2024-02-05T23:58:21.042833059Z          at eShop.Catalog.API.CatalogApi.ChangeUriPlaceholder(CatalogOptions options, List`1 items) in /home/vivazqu/workspace/eshop/eShop/src/Catalog.API/Apis/CatalogApi.cs:line 312
2024-02-05T23:58:21.042839532Z          at eShop.Catalog.API.CatalogApi.GetAllItems(PaginationRequest paginationRequest, CatalogServices services) in /home/vivazqu/workspace/eshop/eShop/src/Catalog.API/Apis/CatalogApi.cs:line 50
2024-02-05T23:58:21.042845252Z          at Microsoft.AspNetCore.Http.RequestDelegateFactory.ExecuteTaskResult[T](Task`1 task, HttpContext httpContext)
2024-02-05T23:58:21.042850562Z          at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
2024-02-05T23:58:21.042865460Z          at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
2024-02-05T23:58:21.042870740Z          at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

Here is the full log from getting the request to the last error in the stack

2024-02-06T00:12:12.841127766Z info: Microsoft.EntityFrameworkCore.Database.Command[20101]
2024-02-06T00:12:12.841188229Z       Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
2024-02-06T00:12:12.841197717Z       SELECT count(*)
2024-02-06T00:12:12.841204239Z       FROM "Catalog" AS c
2024-02-06T00:12:12.843701833Z info: Microsoft.EntityFrameworkCore.Database.Command[20101]
2024-02-06T00:12:12.843724606Z       Executed DbCommand (2ms) [Parameters=[@__p_1='?' (DbType = Int32), @__p_0='?' (DbType = Int32)], CommandType='Text', CommandTimeout='30']
2024-02-06T00:12:12.843734334Z       SELECT c."Id", c."AvailableStock", c."CatalogBrandId", c."CatalogTypeId", c."Description", c."Embedding", c."MaxStockThreshold", c."Name", c."OnReorder", c."PictureFileName", c."Price", c."RestockThreshold"
2024-02-06T00:12:12.843741337Z       FROM "Catalog" AS c
2024-02-06T00:12:12.843749152Z       ORDER BY c."Name"
2024-02-06T00:12:12.843755784Z       LIMIT @__p_1 OFFSET @__p_0
2024-02-06T00:12:12.845458727Z fail: Microsoft.AspNetCore.Server.Kestrel[13]
2024-02-06T00:12:12.845482812Z       Connection id "0HN16KMJOLUDU", Request id "0HN16KMJOLUDU:00000001": An unhandled exception was thrown by the application.
2024-02-06T00:12:12.845490967Z       System.NullReferenceException: Object reference not set to an instance of an object.
2024-02-06T00:12:12.845496748Z          at eShop.Catalog.API.CatalogApi.ChangeUriPlaceholder(CatalogOptions options, List`1 items) in /home/vivazqu/workspace/eshop/eShop/src/Catalog.API/Apis/CatalogApi.cs:line 312
2024-02-06T00:12:12.845502829Z          at eShop.Catalog.API.CatalogApi.GetAllItems(PaginationRequest paginationRequest, CatalogServices services) in /home/vivazqu/workspace/eshop/eShop/src/Catalog.API/Apis/CatalogApi.cs:line 50
2024-02-06T00:12:12.845508229Z          at Microsoft.AspNetCore.Http.RequestDelegateFactory.ExecuteTaskResult[T](Task`1 task, HttpContext httpContext)
2024-02-06T00:12:12.845523878Z          at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
2024-02-06T00:12:12.845530040Z          at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
2024-02-06T00:12:12.845535931Z          at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
2024-02-06T00:12:12.855222730Z info: Microsoft.EntityFrameworkCore.Database.Command[20101]
2024-02-06T00:12:12.855258467Z       Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
2024-02-06T00:12:12.855266742Z       SELECT c."Id", c."Brand"
2024-02-06T00:12:12.855272843Z       FROM "CatalogBrand" AS c
2024-02-06T00:12:12.855278644Z       ORDER BY c."Brand"
2024-02-06T00:12:12.857098797Z info: Microsoft.EntityFrameworkCore.Database.Command[20101]
2024-02-06T00:12:12.857122041Z       Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
2024-02-06T00:12:12.857130136Z       SELECT c."Id", c."Type"
2024-02-06T00:12:12.857136067Z       FROM "CatalogType" AS c
2024-02-06T00:12:12.857141367Z       ORDER BY c."Type"
2024-02-06T00:12:14.131326943Z info: Microsoft.EntityFrameworkCore.Database.Command[20101]
2024-02-06T00:12:14.131357150Z       Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
2024-02-06T00:12:14.131366757Z       SELECT count(*)
2024-02-06T00:12:14.131374222Z       FROM "Catalog" AS c
2024-02-06T00:12:14.133983695Z info: Microsoft.EntityFrameworkCore.Database.Command[20101]
2024-02-06T00:12:14.134010425Z       Executed DbCommand (2ms) [Parameters=[@__p_1='?' (DbType = Int32), @__p_0='?' (DbType = Int32)], CommandType='Text', CommandTimeout='30']
2024-02-06T00:12:14.134020113Z       SELECT c."Id", c."AvailableStock", c."CatalogBrandId", c."CatalogTypeId", c."Description", c."Embedding", c."MaxStockThreshold", c."Name", c."OnReorder", c."PictureFileName", c."Price", c."RestockThreshold"
2024-02-06T00:12:14.134051602Z       FROM "Catalog" AS c
2024-02-06T00:12:14.134058875Z       ORDER BY c."Name"
2024-02-06T00:12:14.134064906Z       LIMIT @__p_1 OFFSET @__p_0
2024-02-06T00:12:14.134879706Z fail: Microsoft.AspNetCore.Server.Kestrel[13]
2024-02-06T00:12:14.134894624Z       Connection id "0HN16KMJOLUDV", Request id "0HN16KMJOLUDV:00000002": An unhandled exception was thrown by the application.
2024-02-06T00:12:14.134901837Z       System.NullReferenceException: Object reference not set to an instance of an object.
2024-02-06T00:12:14.134908971Z          at eShop.Catalog.API.CatalogApi.ChangeUriPlaceholder(CatalogOptions options, List`1 items) in /home/vivazqu/workspace/eshop/eShop/src/Catalog.API/Apis/CatalogApi.cs:line 312
2024-02-06T00:12:14.134915363Z          at eShop.Catalog.API.CatalogApi.GetAllItems(PaginationRequest paginationRequest, CatalogServices services) in /home/vivazqu/workspace/eshop/eShop/src/Catalog.API/Apis/CatalogApi.cs:line 50
2024-02-06T00:12:14.134920773Z          at Microsoft.AspNetCore.Http.RequestDelegateFactory.ExecuteTaskResult[T](Task`1 task, HttpContext httpContext)
2024-02-06T00:12:14.134926063Z          at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
2024-02-06T00:12:14.134942003Z          at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
2024-02-06T00:12:14.134948064Z          at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
2024-02-06T00:12:17.695474269Z info: Microsoft.EntityFrameworkCore.Database.Command[20101]
2024-02-06T00:12:17.695525645Z       Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
2024-02-06T00:12:17.695538870Z       SELECT count(*)
2024-02-06T00:12:17.695545853Z       FROM "Catalog" AS c
2024-02-06T00:12:17.697147386Z info: Microsoft.EntityFrameworkCore.Database.Command[20101]
2024-02-06T00:12:17.697167103Z       Executed DbCommand (1ms) [Parameters=[@__p_1='?' (DbType = Int32), @__p_0='?' (DbType = Int32)], CommandType='Text', CommandTimeout='30']
2024-02-06T00:12:17.697175669Z       SELECT c."Id", c."AvailableStock", c."CatalogBrandId", c."CatalogTypeId", c."Description", c."Embedding", c."MaxStockThreshold", c."Name", c."OnReorder", c."PictureFileName", c."Price", c."RestockThreshold"
2024-02-06T00:12:17.697182612Z       FROM "Catalog" AS c
2024-02-06T00:12:17.697189384Z       ORDER BY c."Name"
2024-02-06T00:12:17.697207508Z       LIMIT @__p_1 OFFSET @__p_0
2024-02-06T00:12:17.698269409Z fail: Microsoft.AspNetCore.Server.Kestrel[13]
2024-02-06T00:12:17.698284367Z       Connection id "0HN16KMJOLUDV", Request id "0HN16KMJOLUDV:00000003": An unhandled exception was thrown by the application.
2024-02-06T00:12:17.698890548Z       System.NullReferenceException: Object reference not set to an instance of an object.
2024-02-06T00:12:17.698904805Z          at eShop.Catalog.API.CatalogApi.ChangeUriPlaceholder(CatalogOptions options, List`1 items) in /home/vivazqu/workspace/eshop/eShop/src/Catalog.API/Apis/CatalogApi.cs:line 312
2024-02-06T00:12:17.699867224Z          at eShop.Catalog.API.CatalogApi.GetAllItems(PaginationRequest paginationRequest, CatalogServices services) in /home/vivazqu/workspace/eshop/eShop/src/Catalog.API/Apis/CatalogApi.cs:line 50
2024-02-06T00:12:17.699882563Z          at Microsoft.AspNetCore.Http.RequestDelegateFactory.ExecuteTaskResult[T](Task`1 task, HttpContext httpContext)
2024-02-06T00:12:17.699889306Z          at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
2024-02-06T00:12:17.699903983Z          at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
2024-02-06T00:12:17.699910024Z          at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
2024-02-06T00:12:19.722875195Z info: Microsoft.EntityFrameworkCore.Database.Command[20101]
2024-02-06T00:12:19.722910040Z       Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
2024-02-06T00:12:19.722919197Z       SELECT count(*)
2024-02-06T00:12:19.722925549Z       FROM "Catalog" AS c
2024-02-06T00:12:19.725415580Z info: Microsoft.EntityFrameworkCore.Database.Command[20101]
2024-02-06T00:12:19.725433714Z       Executed DbCommand (2ms) [Parameters=[@__p_1='?' (DbType = Int32), @__p_0='?' (DbType = Int32)], CommandType='Text', CommandTimeout='30']
2024-02-06T00:12:19.725442320Z       SELECT c."Id", c."AvailableStock", c."CatalogBrandId", c."CatalogTypeId", c."Description", c."Embedding", c."MaxStockThreshold", c."Name", c."OnReorder", c."PictureFileName", c."Price", c."RestockThreshold"
2024-02-06T00:12:19.725448442Z       FROM "Catalog" AS c
2024-02-06T00:12:19.725454383Z       ORDER BY c."Name"
2024-02-06T00:12:19.725460284Z       LIMIT @__p_1 OFFSET @__p_0
2024-02-06T00:12:19.727367215Z fail: Microsoft.AspNetCore.Server.Kestrel[13]
2024-02-06T00:12:19.727388746Z       Connection id "0HN16KMJOLUDV", Request id "0HN16KMJOLUDV:00000004": An unhandled exception was thrown by the application.
2024-02-06T00:12:19.727397542Z       System.NullReferenceException: Object reference not set to an instance of an object.
2024-02-06T00:12:19.727404375Z          at eShop.Catalog.API.CatalogApi.ChangeUriPlaceholder(CatalogOptions options, List`1 items) in /home/vivazqu/workspace/eshop/eShop/src/Catalog.API/Apis/CatalogApi.cs:line 312
2024-02-06T00:12:19.727411288Z          at eShop.Catalog.API.CatalogApi.GetAllItems(PaginationRequest paginationRequest, CatalogServices services) in /home/vivazqu/workspace/eshop/eShop/src/Catalog.API/Apis/CatalogApi.cs:line 50
2024-02-06T00:12:19.727418040Z          at Microsoft.AspNetCore.Http.RequestDelegateFactory.ExecuteTaskResult[T](Task`1 task, HttpContext httpContext)
2024-02-06T00:12:19.727424723Z          at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
2024-02-06T00:12:19.727431876Z          at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
2024-02-06T00:12:19.727438769Z          at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

vhvb1989 avatar Feb 06 '24 00:02 vhvb1989

You're missing the PicBaseUrl from the appsettings.json. It exists in the appsettings.development.json file https://github.com/dotnet/eShop/blob/3b49f61a888656b038b5f044b0d4c5096fc9f073/src/Catalog.API/appsettings.Development.json#L6

BrennanConroy avatar Feb 06 '24 00:02 BrennanConroy

So we need to express this in the apphost right? so it works automagically.

davidfowl avatar Feb 06 '24 01:02 davidfowl

Fixed in https://github.com/dotnet/eShop/pull/166/commits/618f611da6a0d5225e01e45d7a4858cf61b1fa45

davidfowl avatar Feb 06 '24 08:02 davidfowl

@davidfowl did you commit this in somewhere?

jamesmontemagno avatar Mar 27 '24 01:03 jamesmontemagno

@SrushtiPasari94 can you test this out, looks to be fixed

jamesmontemagno avatar Mar 28 '24 15:03 jamesmontemagno

This is good now.

adityamandaleeka avatar Apr 10 '24 22:04 adityamandaleeka