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:
EHTTPServer: Error reading data from the socket
My HTTP server is configured approximately as follows:
fphttpapp.Application.Threaded := False;
fphttpapp.Application.AcceptIdleTimeout := 200;
fphttpapp.Application.OnAcceptIdle := @AcceptIdle;
fphttpapp.Application.HTTPHandler.HTTPServer.OnGetSocketHandler :=
@GetSocketHandler;
fphttpapp.Application.HTTPHandler.Run;
I also use a custom socket handler:
function TAQTimeoutSocketHandler.Accept: Boolean;
begin
Result := inherited Accept;
if Result then
Socket.IOTimeout := 10000;
end;
**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!