ChromiumHtmlToPdf icon indicating copy to clipboard operation
ChromiumHtmlToPdf copied to clipboard

Websocket connection timed out

Open decomoraes opened this issue 2 years ago • 2 comments

Hi Sicos1977, first of all I would like to thank you for this framework, the result is perfect.

I created an asp net core api to convert the pdf, but I'm having a issue sometimes, and I'm trying to fix but I cannot find any way to do that. Im hosting it using a docker container, but sometimes the web socket error happens even when I'm debugging. I will share with you the error message and I really appreciate your help in advance.

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HMJME93RHDUI", Request id "0HMJME93RHDUI:00000002": An unhandled exception was thrown by the application.
      ChromeHtmlToPdfLib.Exceptions.ChromeException: Websocket connection timed out after 30 seconds with the state 'Connecting'
         at ChromeHtmlToPdfLib.Converter.StartChromeHeadless()
         at ChromeHtmlToPdfLib.Converter.Convert(OutputFormat outputFormat, Object input, Stream outputStream, PageSettings pageSettings, String waitForWindowStatus, Int32 waitForWindowsStatusTimeout, Nullable`1 conversionTimeout, Nullable`1 mediaLoadTimeout, ILogger logger)
         at ChromeHtmlToPdfLib.Converter.ConvertToPdf(String html, Stream outputStream, PageSettings pageSettings, String waitForWindowStatus, Int32 waitForWindowsStatusTimeout, Nullable`1 conversionTimeout, Nullable`1 mediaLoadTimeout, ILogger logger)
         at PdfMaker.Engines.ConverterEngineV2.ManipulatePdf(MemoryStream& stream) in /Users/decomoraes/Code/Akttom/LIPdfMaker/PdfMaker/src/Applications/Engines/ConverterEngineV2.cs:line 90
         at PdfMaker.Engines.ConverterEngineV2..ctor(Converter converter, Boolean fixPagination) in /Users/decomoraes/Code/Akttom/LIPdfMaker/PdfMaker/src/Applications/Engines/ConverterEngineV2.cs:line 29
         at PdfMaker.UseCases.ExecuteConvertion.Execute(ExecuteConvertionRequest props, Boolean fixPagination) in /Users/decomoraes/Code/Akttom/LIPdfMaker/PdfMaker/src/Applications/UseCases/ExecuteConvertion/ExecuteConvertion.cs:line 69
         at PdfMaker.Controllers.ConverterController.ConverterFromForm(ExecuteConvertionRequest request) in /Users/decomoraes/Code/Akttom/LIPdfMaker/PdfMaker/src/Infra/Http/ConverterController.cs:line 21
         at lambda_method3(Closure , Object , Object[] )
         at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
         at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
         at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
         at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

decomoraes avatar Aug 04 '22 23:08 decomoraes

Well it seems that Chrome does not responed, can you somehow check if Chrome is started?

And is still happening all the time or sometimes?

Sicos1977 avatar Aug 05 '22 04:08 Sicos1977

Yes, I think so, It happens sometimes and the problem is because I'm using an API service, I tested some concurrence, something like 4 simultaneous, I think the chrome is opening multiple instances and could not handle because the memory usage, I don't know, have some way to use tabs instead a new instance?

decomoraes avatar Aug 05 '22 19:08 decomoraes

Hi. I'm not sure if it's the case, but we managed to resolve same problem through replacing WebSocket4Net socket to System.Net.WebSockets.ClientWebSocket. We using this on Linux with Chromium.

I failed in definition of exact conditions of exception because of time. Sometimes connection timed out on devtools, sometimes on page creation. Even if only one conversion job was in progress. But i can say that before replacing i could easily reproduce situation but now i can't.

Sicos1977, can you please tell why WebSocket4Net in general? On project page request not to use because of early stage. Moreover project looks abandoned without changes already nearly two years.

Paraxenate avatar Aug 23 '22 17:08 Paraxenate

To be honnest, I even did not know there was a standard websocket option inside the dotnet framework. The only reason I used WebSocket4Net is because it had the highest download count on nuget :-)

Sicos1977 avatar Aug 23 '22 17:08 Sicos1977

I'm happy to receive a pull request that replaces websocket4net.

Sicos1977 avatar Aug 23 '22 17:08 Sicos1977

I'm sure do but not too soon. If not in weekends then in vacation time in september. Right now i don't have much spare time.

I can't create PR from our patch because that is very raw. We have a plan to rework it later, now all we need that just something working stable.

Paraxenate avatar Aug 24 '22 04:08 Paraxenate

Same problem here, time wise. But at the moment I'm not in a hurry to replace it.

Sicos1977 avatar Aug 24 '22 04:08 Sicos1977

Sorry for being late, had some problems to solve. There is.

Paraxenate avatar Oct 29 '22 09:10 Paraxenate