#1 Re: mORMot 2 » High-Performance Frameworks » 2024-11-18 21:12:30

@ab Yes mem issue is outside of pipeline.
Today we had such an issue in our program (of course without pipeline):

SOneSrv2: malloc.c:4302: _int_malloc: Assertion `(unsigned long) (size) >= (unsigned long) (nb)' failed

We had no error in Postgres log at all. But we are using cmem.

#2 Re: mORMot 2 » SynZip in c# » 2024-11-05 20:16:53

@ebekman Congrats, you're almost there! SynZip is able to decompress your data. The pascal example from @zen010101 is working.

Now you need somebody who create a pascal .dll/.so for you that can be called from your c#.

#3 Re: mORMot 2 » threadvar // do not publish for compilation within Delphi packages » 2024-11-05 13:34:21

Threadvar's are created in a special memory area (thread-local storage). At compile time the addresses of that space for a thread created at runtime isn't fix.
Therefore libraries linked at compile time (which packages are) could have an issue with threadvar's. Dynamically loaded libraries are fine, because they will loaded at runtime, when the threads run.

Because of this it doesn't matter whether a threadvar is declared in interface or implementation part.

#4 Re: mORMot 2 » Validating JWT from JWKS certs in OAuth2 » 2024-11-01 19:32:13

@cadnan works and is much easier than my version, thanks.

but you shouldn't forget

try
...
finally
  FToken.Free;
end;

#5 Re: mORMot 2 » Validating JWT from JWKS certs in OAuth2 » 2024-11-01 14:35:51

I've implemented this task some time ago to check if I could handle it. It's not so easy, but perhaps the situation is more easy if I would have a real AD.

To verify the JWT you need the public key.
The public key in pem format you get from the x5c value. In my test case (at microsoft) the key changes every time (I can't remember the interval e.g. every 30 days).
To get it you have to call -> https://login.microsoftonline.com/'+ response.tenantId +'/discovery/v2.0/keys?appid=...
and compare the kid included in the JWT which you want to verify.

If you have the public key you can verify the JWT with this func:

function VerifyJWT(const aJWT: RawByteString; const aPublicKey: RawByteString; out JWT: Variant): Boolean;
  function VerifyWithmORMot(const aJWT: RawByteString; out JWT: Variant): Boolean;
  var
    Header, Payload, Signature: RawByteString;
    sigBinary, msgBinary: TBytes;
    idx, step: Integer;
    aBuf: PAnsiChar;
  begin
    Header:= '';
    Payload:= '';
    Signature:= '';
    idx:= 0;
    step:= 0;
    aBuf:= PAnsiChar(aJWT);
    while aBuf[idx] <> '' do begin
       INC(idx);
       if aBuf[idx] = '.' then begin
         INC(step);
         if step=1 then
           SetString(Header, aBuf, idx)
         else
         if step=2 then
           SetString(Payload, aBuf, idx)
         else
           SetString(Signature, aBuf, idx);
         INC(aBuf, idx+1);
         idx:= 0;

       end;
    end;

    if (idx > 0) and (step < 3) then
      SetString(Signature, aBuf, idx);

    JWT:= _Obj([]);
    sigBinary:= Base64UrlDecode(Signature);
    RawByteStringToBytes(Header+'.'+Payload, msgBinary);

    Result:= OpenSslVerify('', '', Pointer(msgBinary), Pointer(aPublicKey), Pointer(sigBinary), Length(msgBinary), Length(aPublicKey), Length(sigBinary));
    if Result then
      JWT:= Js2Var(Base64uriToBin(PAnsiChar(Payload), Length(Payload)));
  end;

begin
  Result:= VerifyWithmORMot(aJWT, JWT);
end;

#6 Re: mORMot 2 » malloc(): unaligned tcache chunk detected » 2024-10-29 20:25:42

I've changed our code to get a stable version of our software. The errors are away.
I know there is no issue in the async/socket part of mORMot. But I don't know what exactly had cause the errors.
My guess is an issue with TSynLocker. Perhaps we haven't use it right or made some mistake in the way of lock/unlock.

#7 Re: mORMot 2 » malloc(): unaligned tcache chunk detected » 2024-10-22 16:44:44

I wrote again because I think it could be useful to stabilize the interfaces/network (mormot.core.interfaces / mormot.core.soa) part of the framework, so it is useful for all users:

My pov is, executing of interfaced methods isn't thread safe in some circumstances. Two parallel (sicSingle) service calls comes and their params will be mixed/override. In my case there are such corrupt bison's in mongodb queries.

@Ab could you please check TInterfaceMethodExecuteCached if there is anything what could go wrong under heaver load? All my wrk tests looks good but the live system has this error behavior and all other processes looks good, also the syslog looks good so far.

I've commented out this part of TInterfaceMethodExecuteCached .Aquire

if fCached.TryLock then
  begin
    // reuse this shared instance between calls
    SetOptions(opt);
    exec := self;
    fCachedWR.CancelAllAsNew;
    WR := fCachedWR;
  end

but its not enough or not the right place.
Are there any other changes in past that comes with https://blog.synopse.info/?post/2022/01 … e-Them-All the that I could test easily?

Perhaps it is not an issue of wrong locking but of not initialization of something reused because of caching?

#8 Re: mORMot 2 » malloc(): unaligned tcache chunk detected » 2024-10-21 08:01:02

Back to the EThreadError the source comes from:

20241021 06575224  . debug  uRestServerDB.TSOneRestServerDB(02eb3298) TServiceFactoryServer.InstanceFree: ignored EThreadError exception during IPersons._Release

So I would love to get further instructions from you.

#9 Re: mORMot 2 » malloc(): unaligned tcache chunk detected » 2024-10-18 15:03:56

Hi ab,

just fyi the error in my service from today and the syslog entries bring me to the nested option for lxc containers and I think I'll give it a try:

https://forum.proxmox.com/threads/lxc-a … -13.36173/

#10 Re: mORMot 2 » GetIt inclusion » 2024-10-18 08:49:21

1. About the tags
1.1 Mainly mORMot is a server lib with features/tools you can't find in other libs. I would start the tags with those word (high performance cross-platform client/server lib for pascal).
1.2 There is a huge cryptographic part connectable with openssl you have all what anyone could want.
1.3 The handling of JSON and Variants is outstanding
1.4 The DB layer is also killer feature and the integration of Zeos makes it complete.

2. The Big Divide
Have I forget something important? Sure. But I would connect this post with The Big divide (https://synopse.info/forum/viewtopic.php?id=7027) and try to find out the main features and try to divide it when possible. So from a marketing pov it really make sense to split mORMmot in 2, 3 or 4 smaller GetIt's.

New users come mostly with specialized requirements and they don't need such a big framework/lib. Everybody of us prefer small specialized and optimized tools against huge ones (E.g. Zeos was the preferred DB-Layer for mORMmot  in past, but than some reinvent the wheel and wrote his own connector for postgres -> yes, this is criticism).

So from marketing pov it really makes a difference and from a technical pov there should be solutions. So why hesitate to do it?

3. Naming
With splitting (point 2) the naming part would be much easier. But I think "mORMot" is misleading although everybody has learned to love it over the years. But are the oldies the future? No. We are talking about a bigger community, right? And therefore we have to focus on the new ones (and mostly younger ones).
ORM was a marketing thing 20 years ago. Why should we keep this name? Let us try to find a better one (or 4 better ones when divided/splitted).

4. Cross-Plattform (my initial thoughts to the last post from @cadnan)
Why hide this really great feature? We can using our software under Windows, Linux, BSD (and ARM). That's amazing! But we hide it because of Delphi? And here I see another big point:

When you @ab drink beer with Marco please suggest him to give up the Delphi compiler and just focus on a IDE for fpc. This is the way to go. Embarcadero could deliver a professional IDE for  the fpc community and the open-source cross-platform compiler (fpc) does all the rest (and we all know he does it very, very good).

Atm I personally developing under Windows because of the high quality of the Delphi-IDE but just to deliver a product compiled with fpc to run on linux. That's not so efficient in my opinion.

Emba could safe much costs (I don't know how many employees work on compiler but there is sure a high potential) and sell much more units with that strategy.

#12 Re: mORMot 2 » malloc(): unaligned tcache chunk detected » 2024-10-16 15:38:58

perThreadLog:= ptIdentifiedInOneFile

This one?

#13 Re: mORMot 2 » malloc(): unaligned tcache chunk detected » 2024-10-16 13:34:29

Here are the relevant log file entries for the EThreadError:

20241016 13290923  -    08.340.038
20241016 13290923 EXC           EThreadError {Message:"Thread error"} [R16:root] at 428014
20241016 13290923 debug         uRestServerDB.TSOneRestServerDB(020bafc8) TServiceFactoryServer.InstanceFree: ignored EThreadError exception during IPersons._Release
20241016 13290923 srvr           192.168.1.214 Interface POST root/Persons.GetOneByID=200 out=3 KB in 4.32s
20241016 13290923 ret           mormot.rest.server.TRestServerRoutingRest(7fdb340cd238) {"result":[{"res": true, ...

The call of the sicSingle service method Persons.GetOneByID is ok from the pov of the client.

This error also comes in case of useHttpSocket (not only with useHttpAsync) and under current mORMot2 branch #38874e16c.

#14 Re: mORMot 2 » malloc(): unaligned tcache chunk detected » 2024-10-16 08:27:20

I've sent you an email with a log file link.

Perhaps this link is interesting for you:

https://stackoverflow.com/questions/693 … ecv-is-suc

I've also read about a hardware issue with ECC RAM but all other programs (postgres, mongodb) run without errors, so I would not go in this direction.

#15 Re: mORMot 2 » malloc(): unaligned tcache chunk detected » 2024-10-15 17:41:54

Yes I hope too.

This error is not really reproducible. I had it the first time since July, but we had several other errors over the last months (e.g. service not responsible or undefined exceptions or the Variant error with with _Safe(v)^.InitArrayFromCsvFile and memory corruption after that) and we have changed a lot of possible bugs on our side but without serious knowledge.

I can change logging to verbose mode and send the file to you (but it's very huge and I will give you an url for downloading per email) but also verbose logging wasn't enough in past. Perhaps adding logs in mormot.net.async or mormot.net.sock is the way to go.

If error is async related could I change to useHttpSocket for testing (in front of our service we are using nginx as reverse proxy)?

->Do you have more info?
Only this errors I had in logfile since last weeks:
20241015 15564437 EXC EThreadError {Message:"Thread error"} [R12:root]
20241015 15564446 EXC EThreadError {Message:"Thread error"} [R14:root]
20241015 15564448 EXC EThreadError {Message:"Thread error"} [R13:root]
20241015 16171856 EXC EThreadError {Message:"Thread error"} [R13:root]
20241015 16171859 EXC EThreadError {Message:"Thread error"} [R8:root]
But it seems to be transparent from the client side, because we have no error responses related to that errors.

Atm I use two services as upstream under nginx (linux as main service and a windows http.sys service as backup). The windows service seems to be more stable as the linux with async server.


->Where/when is it killed?
It's killed from os today. Here are the rows from syslog:
Oct 15 16:09:53 mssql SOneSrv2[358268]: malloc(): unaligned tcache chunk detected
Oct 15 16:09:53 mssql systemd[1]: SOneSrv2.service: Main process exited, code=killed, status=6/ABRT
Oct 15 16:09:53 mssql systemd[1]: SOneSrv2.service: Failed with result 'signal'.
Oct 15 16:09:53 mssql systemd[1]: SOneSrv2.service: Consumed 28min 29.400s CPU time.
Oct 15 16:10:23 mssql systemd[1]: SOneSrv2.service: Scheduled restart job, restart counter is at 1.

->What is the load?
It's difficult to answer.
Per day we have about 400-500 thousand requests with a average request time of 20ms, but there are also request with text search in MongoDB that could run 10s.
We are using an lxc container with 32 cores, 100G mem (60G free) and zfs. Our service has 32 worker threads and there are about 100-200 concurrent users.
The cpu-usage is mostly under 10% but for some seconds over 100% because MongoDB is heavily used in front of postgres. But I would say we don't have any overload here.

#16 mORMot 2 » malloc(): unaligned tcache chunk detected » 2024-10-15 14:55:11

danielkuettner
Replies: 15

Hi Arnaud,

under Linux + fpc 3.2.0 -O3 http async (epoll) built with mORMot2 1c3447f4 (2024-09-17) and I'm using cmem.
I've got that error and our service was killed by os (ubuntu).

Is that error known and fixed in a later version?

#17 Re: mORMot 2 » issue with _Safe and InitArrayFromCsvFile » 2024-10-03 07:11:19

I wouldn't change so much. My confusing results from working with your tools and not understanding much of it in depth. Some points you understand after years.

But perhaps some small improvements could help.
That _Safe could return a read only fake DocVariantData is perhaps a little bit too much and contrary to the name „_safe“.

#19 Re: mORMot 2 » issue with _Safe and InitArrayFromCsvFile » 2024-10-03 06:04:52

A clear after each Init is necessary because Variants are managed types, right?
Otherwise the compiler would free a Variant which may be still in using because of a duplicate Init

#20 Re: mORMot 2 » issue with _Safe and InitArrayFromCsvFile » 2024-10-02 20:05:57

Ok, @tbo thanks for your good and detailed article.
@ab thanks for your outstanding framework. I'm fare from any critic at all.

But I just can't find any forbidden at this (also after reading your article @tbo):

v:= _ARR([]);
_Safe(v)^.InitArrayFromCsvFile('f1,f2,f3'#10'"1";"2";"3"', [], ',','"');

It seems to work, but am I wrong?

How should I call clear here? What would clear do with an empty []?

I just ask to understand and learn, not to annoy.

#21 Re: mORMot 2 » issue with _Safe and InitArrayFromCsvFile » 2024-10-02 18:31:25

Ok, but what’s wrong with a re-initialize of a variant? I could re-initialize it who often I want?
It’s only one variant on the stack and not a class-instance of a create constructor.
I create a Variant with _ARR and will fill this Variant with the data of a csv.
Is the using of _Safe(of a Variant of type 271) in this case so clearly senseless?

#22 Re: mORMot 2 » issue with _Safe and InitArrayFromCsvFile » 2024-10-02 18:00:02

Can you explain a little bit. I don't know why it does make any sense.

_Safe(aVariant) gives a TDocVariantData record back and this type has the method InitArrayFromCsvFile.

#23 mORMot 2 » issue with _Safe and InitArrayFromCsvFile » 2024-10-02 10:00:44

danielkuettner
Replies: 15

Hi ab,

the using of InitArrayFromCsvFile in this context overrides memory and results in unexpected behavior:

_Safe(aVariant)^.InitArrayFromCsvFile(aRawUtf8data, [], ';', '"');

But when using a TDocVariantData I can use InitArrayFromCsvFile without issues:

aDocVariantData.InitArrayFromCsvFile(aRawUtf8data, [], ';', '"');

Do you have what's the background of that?

#24 Re: mORMot 2 » Cannot switch RegisterCustomJSONSerializerFromText to mORMot2 » 2024-08-07 14:35:21

perhaps this info in mormot.core.text.pas can help:

// - note: mORMot 1.18 TTextWriter.RegisterCustomJSONSerializerFromText()
  // are moved into Rtti.RegisterFromText() as other similar methods

P.S.
We also have contact with Ingenico

#26 Re: mORMot 2 » issue with new IsContentTypeCompressible(pointer(OutContentType)) » 2024-07-26 14:55:23

I'm not the one who defines which ContentType hast to be compressed. But over the last 10 years I'm using this ContentType and it was never compressed.
Should be compressing not independent from ContentTypes and compressing tagged by other headers:

Content-Type:application/json - tells what type of content data in the http call
Content-Encoding: gzip - tells what compression being used

Anyway, I need a way to disable compressing, because it isn't nice to decompress synlz compressed responses by browser/js.

#27 mORMot 2 » issue with new IsContentTypeCompressible(pointer(OutContentType)) » 2024-07-26 08:41:09

danielkuettner
Replies: 6

Hi ab,

since commit #ebba3ec http response in browser client is compressed because of this line in mormot.net.http.pas:

compressible := IsContentTypeCompressible(pointer(OutContentType));

Do I have to set/config something to prevent this?
My ContentType is application/json.

When changing line 8903 in mormot.core.buffers.pas to this

_CONTENT_APP: array[0..4] of PUtf8Char = (
    'APPLICATION/JSON', <-- this works for me
    'XML',
    'JAVASCRIPT',
    'VND.API+JSON',
    nil);

it work as expected.

Daniel

#28 Re: mORMot 2 » Performance of Mormot Collections vs. Spring v2 Collections » 2023-11-27 10:37:54

I'm aware I'm not speaking for the whole mOMRot community, but in our project we can get without generics. But without mORMot using Delphi/Pascal were impossible.

Thats all what I can say to this topic from side.

#29 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-11-08 10:41:39

In TRttiCustomList.DoRegister Info.KIND has rkBOOL.
But Instance (Result) will not set after GlobalClass.Create and given to AddToPairs(result, Info);

In AddToPairs I can't see from where Instance is getting his KIND (it's just rkUnknown) until inc(Counts[Instance.Kind]);

#30 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-11-07 15:42:06

Yes, with your last patch it works as expected.

Yes, it was rkUnknown.

#31 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-11-07 10:45:54

I've tested and changed code in a very unprofessional way and maybe I'm lost, but I want to share my guess founded in mormon.core.rtti:

The address of the CS will be changed through line 8730 in TRttiCustomList.AddToPairs:

inc(Counts[Instance.Kind]);

After that the RegisterSafe.UnLock; in line 9002 goes with the wrong Pointer address in mutex_unlock_common and therefore it results in a segfault.

If I comment line 8730 the segfault is away and also my real app is running under FreeBSD 13.2 as under Win/Linux.

But I don't know, what's the meaning of line 9002 and the drawbacks of that.

#32 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-11-02 09:07:26

Yes, I do always a clean & build under lazarus. But mormot.core.linux.inc? Do you mean mormot.core.os.posix.inc?

#33 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-11-01 16:52:12

Please look at the stack trace from lazarus. Is #1 und #2 double or normal?
I'm not able to debug constructive (perhaps because of inlining).

#0 mutex_unlock_common(0x9013d1708, false, 0x0) at /usr/src/lib/libthr/thread/thr_mutex.c:976
#1 CTHREADS_$$_CLEAVECRITICALSECTION$formal at :0
#2 SYSTEM_$$_LEAVECRITICALSECTION$POINTER at :0
#3 DOREGISTER(0x801cef6a0, 0xe3d8d8) at ../../mORMot2/src/core/mormot.core.rtti.pas:8630
#4 SETGLOBALCLASS(0x801cef6a0, 0xf8af30) at ../../mORMot2/src/core/mormot.core.rtti.pas:8751
#5 INITIALIZEUNIT at ../../mORMot2/src/core/mormot.core.json.pas:11687
#6 MORMOT.CORE.JSON_$$_init$ at ../../mORMot2/src/core/mormot.core.json.pas:11699
#7 fpc_initializeunits at :0
#8 main at SOneSrv2.dpr:551

#34 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-11-01 14:34:19

Ok, than no progress at all:

mutex_unlock_common (m=0x90134b708, cv=false, mtx_defer=0x0)
    at /usr/src/lib/libthr/thread/thr_mutex.c:976
976        if (__predict_false(PMUTEX_OWNER_ID(m) != id))
(gdb) backtrace 10
#0  mutex_unlock_common (m=0x90134b708, cv=false, mtx_defer=0x0)
    at /usr/src/lib/libthr/thread/thr_mutex.c:976
#1  0x0000000000434b49 in CTHREADS_$$_CLEAVECRITICALSECTION$formal ()
#2  0x00000000004254ca in SYSTEM_$$_LEAVECRITICALSECTION$POINTER ()
#3  0x00000000004dcae3 in DOREGISTER (this=0x801de8370, INFO=0xeb7b68)
    at ../../mORMot2/src/core/mormot.core.rtti.pas:8630
#4  0x00000000004dd357 in SETGLOBALCLASS (this=0x801de8370,
    RTTICLASS=0x1004fa0) at ../../mORMot2/src/core/mormot.core.rtti.pas:8751
#5  0x000000000094f8bd in INITIALIZEUNIT ()
    at ../../mORMot2/src/core/mormot.core.json.pas:11687
#6  0x000000000094f979 in MORMOT.CORE.JSON_$$_init$ ()
    at ../../mORMot2/src/core/mormot.core.json.pas:11699
#7  0x0000000000421652 in fpc_initializeunits ()
#8  0x0000000000403b9f in main () at SOneSrv2.dpr:551

If a do a breakpoint in thr_mutex.c for mutex_lock_common and mutex_unlock_common, than I can see, that this function will be called.
Are you sure, a confusion of libc and libthr functions exists?

#35 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-11-01 08:22:20

I've applied your commit, but
how can I remove the reference to clib in mormot.core.os.posix.inc? There are other functions (e.g. clock_gettime) needing clib.
Do I need cthreads anymore? We have disabled MemoryManager for testing.

#36 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-11-01 07:39:59

@DonAlfredo
This patch is already included in R13.2 and it couldn't be an issue on linker side.

Thanks a lot for your hint!

#37 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-10-31 18:32:20

@DonAlfredo
Thanks for this link. I've alfredy (joke) read about this issue. But the patch is fro 2019 and I've the R13.2 from Apr 2023 and should the backtrace not shown something of libc in such a case? But I will compare the patch with the current source files and perhaps that will help.

#38 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-10-31 17:14:52

with TLightLock app hangs when leaving InizializeUnit in mormot.core.log. After stepping over end; Debugger shows end; of FinalizeUnit.

Assembler show this:
0000000000421472 eb55                     jmp    0x4214c9 <fpc_initializeunits+121>

0000000000421474 48c745f800000000         movq   $0x0,-0x8(%rbp)
000000000042147C 488b45f8                 mov    -0x8(%rbp),%rax
0000000000421480 488d4001                 lea    0x1(%rax),%rax
0000000000421484 488945f8                 mov    %rax,-0x8(%rbp)
0000000000421488 488b45f8                 mov    -0x8(%rbp),%rax
000000000042148C 48c1e004                 shl    $0x4,%rax
0000000000421490 488d15a99ba100           lea    0xa19ba9(%rip),%rdx        # 0xe3b040 <INITFINAL>
0000000000421497 48833c0200               cmpq   $0x0,(%rdx,%rax,1)
000000000042149C 7502                     jne    0x4214a0 <fpc_initializeunits+80>
000000000042149E eb12                     jmp    0x4214b2 <fpc_initializeunits+98>
00000000004214A0 488b45f8                 mov    -0x8(%rbp),%rax
00000000004214A4 48c1e004                 shl    $0x4,%rax
00000000004214A8 488d15919ba100           lea    0xa19b91(%rip),%rdx        # 0xe3b040 <INITFINAL>
00000000004214AF ff1402                   call   *(%rdx,%rax,1)
00000000004214B2 488d05879ba100           lea    0xa19b87(%rip),%rax        # 0xe3b040 <INITFINAL>
00000000004214B9 488b55f8                 mov    -0x8(%rbp),%rdx
00000000004214BD 48895008                 mov    %rdx,0x8(%rax)
00000000004214C1 483b5df8                 cmp    -0x8(%rbp),%rbx
00000000004214C5 7602                     jbe    0x4214c9 <fpc_initializeunits+121>
00000000004214C7 ebb3                     jmp    0x42147c <fpc_initializeunits+44>
00000000004214C9 488d0550aea100           lea    0xa1ae50(%rip),%rax        # 0xe3c320 <TC_$SYSTEM_$$_INITPROC>
00000000004214D0 48833800                 cmpq   $0x0,(%rax)
00000000004214D4 7502                     jne    0x4214d8 <fpc_initializeunits+136>
00000000004214D6 eb09                     jmp    0x4214e1 <fpc_initializeunits+145>
00000000004214D8 488d0541aea100           lea    0xa1ae41(%rip),%rax        # 0xe3c320 <TC_$SYSTEM_$$_INITPROC>
00000000004214DF ff10                     call   *(%rax)
00000000004214E1 488b5df0                 mov    -0x10(%rbp),%rbx
00000000004214E5 4889ec                   mov    %rbp,%rsp
00000000004214E8 5d                       pop    %rbp

#39 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-10-31 16:59:38

Thanks, with TLightLock app hangs again.

With TOSLightLock segfault again:

#0  mutex_unlock_common (m=0x90134b708, cv=false, mtx_defer=0x0)
    at /usr/src/lib/libthr/thread/thr_mutex.c:976
#1  0x00000000004dcae3 in DOREGISTER (this=0x801de8370, INFO=0xeb7b68)
    at ../../mORMot2/src/core/mormot.core.rtti.pas:8630
#2  0x00000000004dd357 in SETGLOBALCLASS (this=0x801de8370, RTTICLASS=0x1004fa0)
    at ../../mORMot2/src/core/mormot.core.rtti.pas:8751
#3  0x000000000094f8bd in INITIALIZEUNIT ()
    at ../../mORMot2/src/core/mormot.core.json.pas:11687
#4  0x000000000094f979 in MORMOT.CORE.JSON_$$_init$ ()
    at ../../mORMot2/src/core/mormot.core.json.pas:11699
#5  0x0000000000421652 in fpc_initializeunits ()
#6  0x0000000000403b9f in main () at SOneSrv2.dpr:551

Registers:
rax            0x7fffffff          2147483647
rbx            0x90134b708         38674937608
rcx            0x801349008         34379960328
rdx            0x0                 0
rsi            0x0                 0
rdi            0x90134b708         38674937608
rbp            0x7fffffffd540      0x7fffffffd540
rsp            0x7fffffffd4e0      0x7fffffffd4e0
r8             0x6c6f6f42          1819242306
r9             0x80000             524288
r10            0x4a7b48            4881224
r11            0x0                 0
r12            0x7fffffffd9c0      140737488345536
r13            0x0                 0
r14            0x189be             100798
r15            0x801612000         34382880768
rip            0x800f06a33         0x800f06a33 <mutex_unlock_common+51>
eflags         0x10206             [ PF IF RF ]
cs             0x43                67
ss             0x3b                59
ds             0x3b                59
es             0x3b                59
fs             0x13                19
gs             0x1b                27
fs_base        0x800ef1120         34375405856

#40 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-10-31 13:43:19

Now with TLightLock my real app hangs at starting and I have to find out where.

#41 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-10-31 08:18:31

Please give me some more time to find out next issues, because the main issue resists and just a first step of initialization of the units seems to work…

#43 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-10-30 20:11:52

Yes, I think that's the same issue like the docker one. But it's just my intension, because the av is released at the same time in the same unit initializations.

I've tested your new commit (thank's a lot for your investigation), but got the same segfault as without it:

mutex_unlock_common (m=0x901398708, cv=false, mtx_defer=0x0)
    at /usr/src/lib/libthr/thread/thr_mutex.c:976
976        if (__predict_false(PMUTEX_OWNER_ID(m) != id))
(gdb) bt 10
#0  mutex_unlock_common (m=0x901398708, cv=false, mtx_defer=0x0)
    at /usr/src/lib/libthr/thread/thr_mutex.c:976
#1  0x0000000000431c19 in CTHREADS_$$_CLEAVECRITICALSECTION$formal ()
#2  0x000000000042560a in SYSTEM_$$_LEAVECRITICALSECTION$POINTER ()
#3  0x00000000004d9ea3 in DOREGISTER (this=0x801637188, INFO=0xeb4b58)
    at ../../mORMot2/src/core/mormot.core.rtti.pas:8629
#4  0x00000000004da717 in SETGLOBALCLASS (this=0x801637188, RTTICLASS=0x1001a30)
    at ../../mORMot2/src/core/mormot.core.rtti.pas:8750
#5  0x000000000094ca5d in INITIALIZEUNIT () at ../../mORMot2/src/core/mormot.core.json.pas:11687
#6  0x000000000094cb19 in MORMOT.CORE.JSON_$$_init$ ()
    at ../../mORMot2/src/core/mormot.core.json.pas:11699
#7  0x0000000000421792 in fpc_initializeunits ()
#8  0x0000000000403cdf in main () at SOneSrv2.dpr:550

#44 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-10-30 17:44:42

the segfault comes from thr_mutex.c when the CS will be unlocked a second time:

/*
* Check if the running thread is not the owner of the mutex.
*/
if (__predict_false(PMUTEX_OWNER_ID(m) != id)) <-- here
  return (EPERM);

This comes from the second step of a for loop in mormot.core.rtti which calls

function TRttiCustomList.DoRegister(Info: PRttiInfo): TRttiCustom;

and here the finally RegisterSafe.UnLock;
calls in thr_mutex.c

mutex_unlock_common(struct pthread_mutex *m, bool cv, int *mtx_defer)

stack trace:
#0  mutex_unlock_common (m=0x90138e708, cv=false, mtx_defer=0x0) at /usr/src/lib/libthr/thread/thr_mutex.c:976
#1  0x0000000000431c19 in CTHREADS_$$_CLEAVECRITICALSECTION$formal ()
#2  0x00000000004ee651 in UNLOCK (this=...) at ../../mORMot2/src/core/mormot.core.os.pas:9003
#3  0x00000000004d9e59 in DOREGISTER (this=0x801637188, INFO=0xea9f78) at ../../mORMot2/src/core/mormot.core.rtti.pas:8629
#4  0x00000000004da677 in SETGLOBALCLASS (this=0x801637188, RTTICLASS=0xff6df0) at ../../mORMot2/src/core/mormot.core.rtti.pas:8750
#5  0x000000000094bffd in INITIALIZEUNIT () at ../../mORMot2/src/core/mormot.core.json.pas:11679
#6  0x000000000094c0b9 in MORMOT.CORE.JSON_$$_init$ () at ../../mORMot2/src/core/mormot.core.json.pas:11691
#7  0x0000000000421792 in fpc_initializeunits ()
#8  0x0000000000403cdf in main () at SOneSrv2.dpr:550

#45 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-10-30 17:14:28

I've testet with standard memory manager from fpc and with cmem.
No reallocations of large buffers of my own.
Now I've tested the two defines, but with no success.
(freebsd 13.2, fpc 3.2.2)

#46 Re: mORMot 2 » Error running docker container from ex\martin-doyle\07-HttpDockerORM » 2023-10-29 16:38:54

Same behavior as under FreeBSD.
The AV occurs after unlocking a CriticalSection. I don't think it has to do with an old libc, but with using libthr (instead of libpthread under linux).
I guess it's not an Docker issue rather than an issue of the using image.

I'm not able to find a solution atm. The only thing I've found is the initialization of the CS will be called serveral time in right same thread (the thread of the initialization of the units.
Perhaps the libthr releases a CS when it will be initialized a second time. But it's just a guess.

#47 mORMot 2 » Can't get mORMot2 running under FreeBSD13 » 2023-10-16 15:48:11

danielkuettner
Replies: 1

Although linux is our production environment I'm testing with FreeBSD perhaps as a replacement in future. My last tests some month ago were successful under Proxmox in a FreeBSD13 VM.

Now I'm testing with a real FreeBSD13 host and here I can first compile successfully my program but it comes a runtime exception after starting when mORMot2 initialize a global mutex between initialization und finalization. I've tested with fpc 3.2.0, 3.2.2 and 3.3.1.

gdb show's:

Program received signal SIGSEGV, Segmentation fault.
Address not mapped to object.
mutex_unlock_common (m=0x90139f708, cv=false, mtx_defer=0x0)
    at /usr/src/lib/libthr/thread/thr_mutex.c:973
973        if (__predict_false(PMUTEX_OWNER_ID(m) != id))

Something seems to be different under FreeBSD with /lib/libthr.so.3 compared to /lib/x86_64-linux-gnu/libpthread.so.0 under Linux.

PS:
I've also tried several versions of FreeBSD13 and I've build FreeBSD 13.2 Release from source with connected Kernel.

#48 Re: mORMot 2 » Variant issues under freebsd13 with fpc 3.2.2 » 2023-04-23 17:20:43

Thanks for your hint (after reading I remember).
After patching ncal.pas it just works with 3.2.2 under freebsd!

#49 Re: mORMot 2 » Variant issues under freebsd13 with fpc 3.2.2 » 2023-04-23 12:34:37

Following late binding calls doesn't work:

v._(0)

where v is an _ARR

This post seems related to the issue I have:
https://synopse.info/forum/viewtopic.php?pid=34034

And I know I can work around with using TDocVariant instead of
last binding.

But not using late binding is a regression.

#50 mORMot 2 » Variant issues under freebsd13 with fpc 3.2.2 » 2023-04-22 10:15:52

danielkuettner
Replies: 3

Hi Arnaud,

I could successfully compile our project, but there are runtime av's relating to variants.
Are there patches needed to run under this constellation or should it just work?

Here are a result from mORMot2tests:

#16 4E59E2A5-E8C1-46AB-90E5-F426EC9DBB1E<>4e59e2a5-e8c1-46ab-90e5-f426ec9dbb1e uuid  !  - Dmi smbios: 1 / 44 FAILED  527us
0000000000000000  ! fail  #16 4E59E2A5-E8C1-46AB-90E5-F426EC9DBB1E<>4e59e2a5-e8c1-46ab-90e5-f426ec9dbb1e uuid
000000000018FA8D  ! EXC   ESynVariant {Message:"TDocVariant.DispInvoke: invalid (1) call"} [Main] at 684f2d

Daniel

Board footer

Powered by FluxBB