#1 2025-06-21 19:34:22

testgary
Member
Registered: 2025-02-06
Posts: 27

Access violation writing to address

implementation

{$R *.lfm}

var
  aModel: TOrmModel;
  aServer: TRestServerDB;
  aApplication: TBlogApplication;
  aHTTPServer: TRestHttpServer;
  aHTTPServer443: TRestHttpServer;
  LogFamily: TSynLogFamily;

procedure TForm1.Button1Click(Sender: TObject);
begin
  aModel := CreateModel;
  aServer := TRestServerDB.Create(
    aModel, ChangeFileExt(Executable.ProgramFileName, '.db'));
  aServer.DB.Synchronous := smNormal;
  aServer.DB.LockingMode := lmExclusive;
  aServer.Server.CreateMissingTables;
  aApplication := TBlogApplication.Create;
  aApplication.Start(aServer);

  aHTTPServer443 := TRestHttpServer.Create([aServer], '443', 32, secTLS, HTTPSERVER_DEBUG_OPTIONS,
    'C:\Users\aaa\Desktop\ssl\mycert.pfx',
    'C:\Users\aaa\Desktop\ssl\privkey.pem',
    '|sBcaVv;"f',
    'C:\Users\aaa\Desktop\ssl\cert.pem');
  aHTTPServer443.RootRedirectToURI('blog/default');
  aServer.RootRedirectGet := 'blog/default';


  aHTTPServer := TRestHttpServer.Create('8092', aServer, '+',
    HTTP_DEFAULT_MODE, nil, 16, secNone, '', '', HTTPSERVER_DEBUG_OPTIONS);
  aHTTPServer.RootRedirectToURI('blog/default'); // redirect / to blog/default
  //aHTTPServer.RootRedirectToURI('blog/default', True, True);
  aServer.RootRedirectGet := 'blog/default';     // redirect blog to blog/default
end;   

Convert the mvc-blog example into a program with a form, without making any other changes. Start the program, then open the web page, and then exit the program. At this point, the following error message will appear: "Access violation writing to address $0000000000000024."

I am using Lazarus 3.0.

Of course, you need to access it via https.     https://localhost/blog/default

Last edited by testgary (2025-06-21 19:38:16)

Offline

#2 2025-06-22 09:07:24

flydev
Member
From: France
Registered: 2020-11-27
Posts: 94
Website

Re: Access violation writing to address

I can't reproduce it - it work as expected at least on fpc 3.2.2.

edit: ... and mormot 2.3.10775

Last edited by flydev (2025-06-22 09:10:45)

Offline

#3 2025-06-22 19:37:27

testgary
Member
Registered: 2025-02-06
Posts: 27

Re: Access violation writing to address

flydev wrote:

I can't reproduce it - it work as expected at least on fpc 3.2.2.

edit: ... and mormot 2.3.10775

For testing, I downloaded the latest Lazarus 4.0 RC + mORMot ('2.3.11235'), but I still reproduced the error. I'm not sure if it's my issue or if the code itself is designed that way — it seems necessary to explicitly add the freeing code on exit.

I added the freeing code at the end before exiting, and then the problem did not occur.

Steps to reproduce the error:

Create a new form application, call the units from the mvc-blog example and other necessary units
Run the form application and start it
Open https://localhost/blog/default
Close the form
An error dialog pops up, reproducing the error.


uses
   MVCModel, MVCViewModel;

var
  Form1: TForm1;

  aModel: TOrmModel;
  aServer: TRestServerDB;
  aApplication: TBlogApplication;
  aHTTPServer, aHTTPSServer: TRestHttpServer;
  LogFamily: TSynLogFamily;

implementation

{$R *.lfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  aModel := CreateModel;

  aServer := TRestServerDB.Create(aModel, ChangeFileExt(Executable.ProgramFileName, '.db'));

  aServer.DB.Synchronous := smNormal;
  aServer.DB.LockingMode := lmExclusive;
  aServer.Server.CreateMissingTables;
  aApplication := TBlogApplication.Create;

  aApplication.Start(aServer);
  aHTTPServer := TRestHttpServer.Create('8092', aServer, '+', HTTP_DEFAULT_MODE, nil, 16, secNone, '', '', HTTPSERVER_DEBUG_OPTIONS);

  aHTTPSServer := TRestHttpServer.Create([aServer], '443', 32, secTLS, HTTPSERVER_DEBUG_OPTIONS,
    'C:\Users\ssl\mycert.pfx',
    'C:\Users\ssl\privkey.pem',
    '|&SSSv;"f',
    'C:\Users\ssl\cert.pem');
  aHTTPSServer.RootRedirectToURI('blog/default');
  aServer.RootRedirectGet := 'blog/default';

  aHTTPServer.RootRedirectToURI('blog/default'); // redirect / to blog/default
  aServer.RootRedirectGet := 'blog/default';     // redirect blog to blog/default
end;

procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  aHTTPServer.Free;
  aHTTPSServer.Free;
  aApplication.Free;
  aServer.Free;
end;    

Offline

#4 2025-06-23 04:48:24

Alek
Member
From: Russia
Registered: 2014-07-04
Posts: 63

Re: Access violation writing to address

replace aHTTPSServer.RootRedirectToURI('blog/default'); // redirect / to blog/default

to aHTTPSServer.RootRedirectToURI('blog/default',true,true); // redirect / to blog/default

Last edited by Alek (2025-06-23 04:49:04)

Offline

#5 2025-06-23 06:34:46

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

Re: Access violation writing to address

Check the stack trace, and try to debug a little more, in order to help us find out the cause of this.

And don't forget to state which OS you are using.

Online

#6 2025-06-23 07:23:06

testgary
Member
Registered: 2025-02-06
Posts: 27

Re: Access violation writing to address

unit mormot.core.log;
procedure InitThreadNumber(nfo: PSynLogThreadInfo);
GlobalThreadLock.Lock;  // It seems that the problem lies with this method.

windows11 lazarus 4.0RC

Last edited by testgary (2025-06-23 07:23:35)

Offline

#7 2025-06-23 07:49:10

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

Re: Access violation writing to address

As I wrote: what is the stack trace?

My guess is that the UI layer is calling the TSynLog code after the mormot.core.log unit is finalized.
It may be a problem with the LCL code within Lazarus 4.0 RC.
Please try with https://github.com/synopse/mORMot2/commit/84d5e3560

Online

#8 2025-06-23 09:14:31

testgary
Member
Registered: 2025-02-06
Posts: 27

Re: Access violation writing to address

#0 ntdll:RtlInitializeResource+1251 at :0
#1 ntdll:RtlRaiseStatus+1167 at :0
#2 ntdll:RtlEnterCriticalSection+242 at :0
#3 InitThreadNumber(PSynLogThreadInfo($000000000A7EFFD8)) at mormot.core.log.pas:4628
#4 TSynLog.LockAndDisableExceptions(Failed to read data from register) at mormot.core.log.pas:4716
#5 TSynLog.LogInternalFmt(TSynLog($00000000014DCB40), sllTrace, $000000010057AAF8^: 'UnSubscribe(socket=% seq=%) cnt=% %', PVarRec($000000000A307A98), 4, TObject($00000000014E6930)) at mormot.core.log.pas:5782
#6 TSynLog.DoLog(Internal dereference error, Failed to read data from register, Internal dereference error, Failed to read data from register (while calculating location), Failed to read data from register, Failed to read data from register) at mormot.core.log.pas:5261
#7 TWinIocp.Unsubscribe(Failed to read data from register, Internal dereference error) at mormot.net.sock.windows.inc:1947
#8 TPollAsyncSockets.Stop(TPollAsyncSockets($00000000015075B0), TPollAsyncConnection($000000000AB193B0), 'Fatal Error') at mormot.net.async.pas:1751
#9 TPollAsyncSockets.CloseConnection(TPollAsyncSockets($00000000015075B0), nil, 'Fatal Error') at mormot.net.async.pas:2010

windows11 lazarus 4.0

Offline

#9 2025-06-24 06:51:36

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

Re: Access violation writing to address

Try with a single HTTP server, and with the latest version of the framework.

Also try with a larger stack trace if possible.
Where in FormClose is the GPF triggered?

Online

Board footer

Powered by FluxBB