#1 2025-03-19 14:55:28

youssef
Member
Registered: 2024-08-05
Posts: 18

ERestException with High RefCount When Stopping Server

Hello everybody , I am encountering an issue when stopping my server, which is built using mORMot2. When I close the server, I get the following exception:

  ! EXC ERestException {Message : "TMYRestServerDb.destroy : TRestOrmServerDb.RefCount = 201"} [Main] at 68ad63

Offline

#2 2025-03-19 15:42:51

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,007
Website

Re: ERestException with High RefCount When Stopping Server

I guess your code have a confusion between IRestOrm and TRestOrm instances.
Or you are keeping some references to IRestOrm somewhere in your code, at shutdown.
You need to clean all IRestOrm references before shutting down the server.

Offline

#3 2025-03-20 12:02:36

youssef
Member
Registered: 2024-08-05
Posts: 18

Re: ERestException with High RefCount When Stopping Server

Hello, 

I have a `Start` and `Stop` function for my server. In the `Start` function, I initialize some data in the database by calling multiple initialization functions like: 

initSomething1(varRest: IRestOrm);
{
  varRest.orm.add()
}
initSomething2(varRest: IRestOrm);
{
  varRest.orm.add()
} 

Each of these functions works with `varRest: IRestOrm` to initialize data. 

In the `Stop` function, I free my `TRestHttpServer` and `TRestServerDb` variables as follows: 

procedure TDeamon.Stop;  
begin  
  TSynLog.Enter(self);    

  DbContext.Destroy;  
  restHttpServer.Free;  
  restServerDb.Free;  
end;

To avoid reference count issues, I explicitly set `varRest := nil` in each `initSomething()` function. However, I still encounter the same exception when stopping the server: 

! EXC ERestException {Message : "TINYRestServerDb.destroy : TRestOrmServerDb.RefCount = 201"}

any insights on what could still be holding references to `IRestOrm`?

Offline

Board footer

Powered by FluxBB