Author Topic: EHTTPServer "Error reading data from the socket" with embedded WebView2  (Read 363 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1864
Hi,

I'm developing a Lazarus application that runs an embedded HTTP server (`fphttpapp`) and uses WebView2 inside the application's main form.

The server works normally when accessed through an external browser. However, when I open a survey page using the embedded WebView2 browser, I encounter the following exception:

Quote
EHTTPServer: Error reading data from the socket

My HTTP server is configured approximately as follows:

Code: Pascal  [Select][+][-]
  1. fphttpapp.Application.Threaded := False;
  2. fphttpapp.Application.AcceptIdleTimeout := 200;
  3. fphttpapp.Application.OnAcceptIdle := @AcceptIdle;
  4.  
  5. fphttpapp.Application.HTTPHandler.HTTPServer.OnGetSocketHandler :=
  6.   @GetSocketHandler;
  7.  
  8. fphttpapp.Application.HTTPHandler.Run;
  9.  

I also use a custom socket handler:

Code: Pascal  [Select][+][-]
  1. function TAQTimeoutSocketHandler.Accept: Boolean;
  2. begin
  3.   Result := inherited Accept;
  4.   if Result then
  5.     Socket.IOTimeout := 10000;
  6. end;
  7.  

**What I have observed:**

- Opening `localhost:8080` works normally.
- Opening `localhost:8080/s?kc=TEST_0024` in the embedded WebView2 triggers the exception after approximately 10 seconds, even without user interaction.
- With `IOTimeout := 5000`, the exception occurs after approximately 5 seconds.
- With `IOTimeout := 10000`, it occurs after approximately 10 seconds.
- With `IOTimeout := 0`, the exception disappears, but stopping the server appears to hang.
- Changing `Application.Threaded` to `True` does not eliminate the exception.
- Using an external browser does not reproduce the same issue.

My questions are:

1. Is this expected behavior when `IOTimeout` expires on an idle HTTP connection?
2. How should an embedded `fphttpapp` server handle idle connections without raising `EHTTPServer` exceptions?
3. What is the recommended way to stop the server gracefully when a client connection is still open?

I'm using Lazarus 4.8 on Windows.

I attach the image of my form. You'll see what I mean.

Any suggestions would be appreciated. Thanks!
« Last Edit: October 27, 2026, 04:59:03 am by egsuh »

paweld

  • Hero Member
  • *****
  • Posts: 1799
Re: EHTTPServer "Error reading data from the socket" with embedded WebView2
« Reply #1 on: October 23, 2026, 12:27:55 pm »
Please provide an example - it will make it easier to answer your question.
Please also edit your post - the forum doesn't support Markdown - use BBCode: https://en.wikipedia.org/wiki/BBCode
For pascal: [code=pascal] //your code[/code]
Best regards / Pozdrawiam
paweld

egsuh

  • Hero Member
  • *****
  • Posts: 1864
Re: EHTTPServer "Error reading data from the socket" with embedded WebView2
« Reply #2 on: October 24, 2026, 02:17:10 am »
Hello,

Here I attach the main form file. Following list is the content of aq05_h.lpr.
This program contains a whole http server. Modules of wmaq05is and wmaq05ie are used in httpserver itself.

When I start the http server, and if accessed from separate browser, there are no problem. The problem explained above occurs only when httpserver is accessed from embedded WVBrowser. And recently I found this error does not occur when the compiled program is executed as stand alone, not within Lazarus IDE, and I'd like to confirm this error is ignorable, as this program is made mainly for debugging purpose, i.e. run whithin IDE.


Code: Pascal  [Select][+][-]
  1. program aq05_h;
  2.  
  3. {$mode objfpc}{$H+}
  4. {$APPTYPE GUI}
  5.  
  6. uses
  7.   Interfaces, Forms,
  8.   fpwebfile, fphttpapp,
  9.   wmaq05is, wmaq05ie, fhttpmanager;
  10.  
  11. begin
  12.   RequireDerivedFormResource := True;
  13.  
  14.   fphttpapp.Application.Title := 'AlphaQ HTTP';
  15.   fphttpapp.Application.LegacyRouting := True;
  16.   fphttpapp.Application.DefaultModuleName := 's';
  17.   fphttpapp.Application.Port := 8080;
  18.   PortNumber := fphttpapp.Application.Port;
  19.  
  20.   Forms.Application.Initialize;
  21.   Forms.Application.CreateForm(TAQDebugForm, AQDebugForm);
  22.  
  23.   Forms.Application.Run;
  24. end.
  25.  

 


salvadordf

  • Jr. Member
  • **
  • Posts: 83
    • BriskBard
Re: EHTTPServer "Error reading data from the socket" with embedded WebView2
« Reply #3 on: October 25, 2026, 10:38:22 am »
Hi,

I downloaded your attachment and disabled all non relevant code.

I removed everything except the TAQHTTPThread and TAQTimeoutSocketHandler classes and the functions to start and stop the server. (See the attachment)

That way I could test the server with several external web browsers.

I tried Edge 156.0.4314.42 and also some CEF4Delphi and WebView4Delphi demos.

I started the server in the 8080 port and then I tried to navigate to localhost:8080 in all the browsers.

In all cases, even with Edge, I get the error "EHTTPServer: Error reading data from the socket" and the web browser shows an error too.

I also tried the SimpleServer demo in CEF4Delphi running in the 8080 port and Edge worked correctly.

I know nothing about fphttpapp but perhaps the code in this short test demo needs to be configured differently.

egsuh

  • Hero Member
  • *****
  • Posts: 1864
Re: EHTTPServer "Error reading data from the socket" with embedded WebView2
« Reply #4 on: October 26, 2026, 05:20:49 am »
@salvadordf

Thank you for analyzing my code. You are right --- even outside browsers cause the problems. But I can get my objective, i.e. debugging, by clicking "continue" at the exception message.

I found your example raises the same issue in anyway.
« Last Edit: October 26, 2026, 05:26:51 am by egsuh »

PascalDragon

  • Hero Member
  • *****
  • Posts: 6454
  • Compiler Developer
Re: EHTTPServer "Error reading data from the socket" with embedded WebView2
« Reply #5 on: October 26, 2026, 09:47:37 pm »
Any suggestions would be appreciated. Thanks!

You should be here long enough to know that one uses [code=pascal][/code]-tags for Pascal code, not Markdown.  ::)

egsuh

  • Hero Member
  • *****
  • Posts: 1864
Re: EHTTPServer "Error reading data from the socket" with embedded WebView2
« Reply #6 on: October 27, 2026, 05:00:04 am »
Quote
You should be here long enough to know that one uses tags for Pascal code, not Markdown.  ::)

Sorry. Forgot to change them.

 

TinyPortal © 2005-2018