#1 2018-03-08 11:23:02

Wytze
Member
Registered: 2018-03-07
Posts: 6

THttpServer gives 'WSAETIMEDOUT' error when called from Chrome

Hello, I'm struggling for a while now with an exception:

ECrtSocket ("SockRecvLn 10060 WSAETIMEDOUT [A connection attempt failed because the connected party did not properly respond after a period of time,
or established connection failed because connected host has failed to respond]")

This error only occurs when the server is called from a Chrome browser (Edge is ok).
When I use the THttpApiServer class the error does not occur either.
There is no difference on running the server on windows 10 or linux (using delphi 7 or crossKylix)

The problem is narrowed down to the following code:

program Test;

uses
  {$I SynDprUses.inc}
  SynCommons, SynCrtSock, SynLog;

{$APPTYPE CONSOLE}

type
  TTestServer = class
  private
    fServer: THttpServerGeneric;
  public
    constructor Create;
    destructor Destroy; override;
    function onRequest(Ctxt: THttpServerRequest): cardinal;
  end;

constructor TTestServer.Create;
begin
  fServer := THttpServer.Create('8888', nil, nil, '');
//  fServer := THttpApiServer.Create(false);
//  THttpApiServer(fServer).AddUrl('','8888', False, 'localhost');
  fServer.OnRequest := onRequest;
  with TSynLog.Family do
  begin
    Level := LOG_VERBOSE;
    EchoToConsole := LOG_VERBOSE;
    PerThreadLog := ptIdentifiedInOnFile;
  end;
end;

destructor TTestServer.Destroy;
begin
  fServer.Free;
  inherited;
end;

function TTestServer.onRequest(Ctxt: THttpServerRequest): cardinal;
begin
  Writeln('Hello!');
  Ctxt.OutContentType := HTML_CONTENT_TYPE;
  Ctxt.OutContent := 'Hello!';
  Result := 200;
end;

var
  LServer: TTestServer;

begin
  LServer := TTestServer.Create;
  Writeln('Server localhost:8888');
  Readln;
  LServer.Free;
end.

In this sample the server keeps running.
But in the server application I've created which uses TWebSocketServer and runs in a Docker container on Linux, the application stops working after a while with several exceptions.
Further our Angular client application takes a few seconds to start (after the WSAETIMEDOUT error is reported).

I hope this explains the problem sufficiently.
Help would be much appreciated.

Last edited by Wytze (2018-03-08 11:30:13)

Offline

#2 2018-03-08 13:52:14

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: THttpServer gives 'WSAETIMEDOUT' error when called from Chrome

Are you using the latest revision of the framework?
Current is 1.18.4400.

We did a lot of fixes in the socket-based server.
Under Linux, it is expected to run this server on the loopback, behind a nginx front-end (for DoS and https).

Offline

#3 2018-03-08 15:32:45

Wytze
Member
Registered: 2018-03-07
Posts: 6

Re: THttpServer gives 'WSAETIMEDOUT' error when called from Chrome

Thanks for the quick reply,
I've just updated from 1.18.4363 to 1.18.4402.
Saw some interesting changes, which might help the Linux application stability.
However also: sad [CrossKylix] DEBUG: C:/Dev/struct/mORMot/SynCrtSock.pas(11002) Error: Constant expression violates subrange bounds.
The corresponding code: curl.Module := -1; // don't try to load any more
Code is introduced in 1.18.4397.

The 'WSAETIMEDOUT' error on Windows 10 is still there.

Last edited by Wytze (2018-03-08 15:33:33)

Offline

#4 2018-03-09 01:04:57

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: THttpServer gives 'WSAETIMEDOUT' error when called from Chrome

I've fixed the Kylix problem via https://synopse.info/fossil/info/41ea0d4330

But I am not able to reproduce your WSAETIMEDOUT on Windows 10 + Chrome.
Also note that using writeln() is never a good idea in a multi-threaded server application.

Offline

#5 2018-03-09 15:08:55

Wytze
Member
Registered: 2018-03-07
Posts: 6

Re: THttpServer gives 'WSAETIMEDOUT' error when called from Chrome

Great, the linux build is working again and hasn't broken yet.

Removed the WriteLn in the 'onRequest' function (was no need for that).

Concerning the 'WSAETIMEDOUT' error reproduction, maybe I must add that there is no reverseproxy running inbetween.
When I run e.g. Fiddler the error does not occur.

Offline

#6 2019-09-12 13:51:46

fravemel
Member
Registered: 2018-08-08
Posts: 5

Re: THttpServer gives 'WSAETIMEDOUT' error when called from Chrome

I'm facing the same exception on windows 10 whith last mormot, compiled with delph 10.3.:
ECrtSocket ("SockRecvLn [10060 WSAETIMEDOUT
When opening any web browser calling a server defined as useBidirSocket, for example:
    HttpServer := TSQLHttpServer.Create('8080',[ServerDB],'+',useBidirSocket);
If I open it from a client aplication or define it "HttpServer := TSQLHttpServer.Create('8080', [ServerDB])" it works ok.


Am I doing anything wrong or mising something?
Any Clue?

Thanks in advance.

Offline

#7 2019-09-13 07:42:19

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: THttpServer gives 'WSAETIMEDOUT' error when called from Chrome

I am not able to reproduce it.

Sounds like a URI registration / Firewal issue to me.

Do the regression tests (TestSQL3.dpr) run as expected on you machine?
Could you try sample "04 - HTTP Client-Server" and check if it works as expected?

Offline

#8 2019-09-17 10:29:27

fravemel
Member
Registered: 2018-08-08
Posts: 5

Re: THttpServer gives 'WSAETIMEDOUT' error when called from Chrome

My fault, after doin the tests you mention, I realiced that the exception was catched and only shows in debug or vervose_log. (data was returned ok even in the browser)
Maybe is the normal behabiour, just a little weird that only appears when accessing from web browser.


I write done the test you said anyway:

sample "04 - HTTP Client-Server" with client and server exe run ok, accessing via web browser shows security:
{
"errorCode":403,
"errorText":"Authentication Failed: Invalid signature (0)"
}

The regresion test failed till I disabled kaspersky antivirus, but the problem with the exception remains after disabling kaspersky even after disabling windows firewall.

Windows 10 64bit (10.0.15063) (cp1252)
    2 x Intel(R) Core(TM) i7-6820EQ CPU @ 2.80GHz (x86)
Using mORMot 1.18.5334
    TSQLite3LibraryStatic 3.29.0 with internal MM
Generated with: Delphi 10.3 Rio 32 bit compiler

Time elapsed for all tests: 2m32
Performed 2019-09-17 11:23:28 by admin on WIN10-POR104

Total assertions failed for all test suits:  0 / 41,844,695
! All tests passed successfully.


I've also tryed to set timeout and call to WebSocketsEnable like sample 31:
    TWebSocketServerRest(HttpServer).ServerKeepAliveTimeOut := 3000;
    { WebSocketServerRest := } HttpServer.WebSocketsEnable(ServerDB, '', False, False);

Offline

#9 2019-09-18 07:17:39

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: THttpServer gives 'WSAETIMEDOUT' error when called from Chrome

I guess the problem is that you main run the server in the IDE debugger, or your computer doesn't have enough computing power.
The Delphi debugger is not able to handle multiple threads in a proper manner, so I have seen some queries abort with a timeout error message, e.g. when running TestSQL3 regression tests.
Running a server in the Delphi debugger may not work as expected, especially if you are pausing the debugging session - other threads are also suspended.

I guess the firewall is not the problem here.
But your AntiVirus is most probably intercepting the socket connection on the loopback, taking a lot of CPU.
2 cores (I guess in your VM) may not be enough with Kaspersky enabled. I personnally use Nod32, putting TestSQL3.exe in the exception list.

Offline

Board footer

Powered by FluxBB