#1 2014-07-22 14:28:35

jrvoorhorst
Member
Registered: 2014-06-06
Posts: 14

Server app runs out of Windows Handles

Hello,

it seems there is a Windows handle leak in mormot server. For every call to my service there are 5 handles added in my app (empty test service function).
So after running for some hours, or after heavy testing with SoapUI,  there are access violations at unexpected places in my app.

I check the handle count with this function:

function GetProcessHandleCount(const hProcess: DWORD;
  var pdwHandleCount: DWORD): BOOL; stdcall; external 'kernel32.dll';

Is this a known problem and how can I solve it? Could the build in caching the source of this problem?

I use rest server in sicSingle mode.

thanks for your reply,

Offline

#2 2014-07-22 14:58:57

jrvoorhorst
Member
Registered: 2014-06-06
Posts: 14

Re: Server app runs out of Windows Handles

Hello,

I am nearer to the source of this problem:

function TUploader.CheckIP: Boolean;
var
  ip, ident: String;
  con: TOleDBMSSQL2008ConnectionProperties;

  function do_check(con: TOleDBMSSQL2008ConnectionProperties): Boolean;
  var
    ips: ISQLDBRows;
  begin
    Result := False;
    if not assigned(con) then
      Exit;

    ips := con.Execute('SELECT identifier FROM AllowedSenders WHERE IP=?',[ip]);
    while ips.Step do
    begin
      if VarToStrDef(ips['identifier'],'') = ident then
      begin
         Result := True;
         Exit;
      end;
    end;

  end;

begin
  Result := False;
  ip := FindIniNameValue(pointer(ServiceContext.Request.Call.InHead),'REMOTEIP: ');
  if ip = '' then
    Exit;
  ident := GetURLParam('Identifier');
  if ident = '' then
    Exit;


  con := dtmlConfig.CreateDBConnection;
  try
    Result := do_check(con);
  finally
    con.Free;
  end;

end;

When I use this code, it leaves me with 3 windows Handles. Problem is in function do_check().

Last edited by jrvoorhorst (2014-07-22 15:00:02)

Offline

#3 2014-07-22 18:01:11

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

Re: Server app runs out of Windows Handles

For which db?

Online

#4 2014-07-23 06:16:53

jrvoorhorst
Member
Registered: 2014-06-06
Posts: 14

Re: Server app runs out of Windows Handles

O, excuse me. I use the TOleDBMSSQL2008ConnectionProperties db connector.

It is created in the CreateDBConnection function.


Or is it better to have one global db connection and use it from all threads?

regards!

Last edited by jrvoorhorst (2014-07-23 06:17:38)

Offline

#5 2014-07-25 07:34:05

jrvoorhorst
Member
Registered: 2014-06-06
Posts: 14

Re: Server app runs out of Windows Handles

Hi ab,

please do you have any idea where I have to look for an solution? It seems te be something in the Connection.Execute functie.

Thanks!

Offline

#6 2014-07-25 09:42:59

jrvoorhorst
Member
Registered: 2014-06-06
Posts: 14

Re: Server app runs out of Windows Handles

One step further, I located the creation of the handles in function procedure SynOleDB.TOleDBConnection.Connect;

    // open the connection to the DB
    OleDBCheck(fDBInitialize.Initialize);

I assume the connection is not closed before destroying the connection. I will look further on it.

Offline

Board footer

Powered by FluxBB