#1 Re: mORMot 2 » Create/sign jwt using Hardware Security Modules (HSM) usb token » 2026-06-09 11:25:21

I success Sign using low level mormot.lib.pkcs11 and high level mormot.crypt.pkcs11.
One of my usb token raise exception at TCryptCertPkcs11.Create
          CKO_CERTIFICATE:
            if fX509 <> nil then
              RaiseError('Create: duplicated certificates')
First two certificate CA Root and CA return empty string StorageID=''. Small changes at TCryptCertAlgoPkcs11.BackgroundLoad, resolve the problem

        for j := 0 to high(obj) do
          if (obj[j].ObjClass in [CKO_CERTIFICATE, CKO_PUBLIC_KEY]) and
             (obj[j].StorageID<>'') then  // Add
            AddRawUtf8(ids, obj[j].StorageID, {nodup=}true);

My second usb token raise exception  with fX509.LoadFromDer. Small changes at TCryptCertPkcs11.Create, resolve the problem

          CKO_CERTIFICATE:
            if fX509 <> nil then
              RaiseError('Create: duplicated certificates')
            else
            begin
              fX509 := TX509.Create;
              if not fX509.LoadFromDer(aValues[i]) then
              begin
                FreeAndNilSafe(fX509);
                // RaiseError('Create: invalid CKO_CERTIFICATE content');   Just ignore this certificates
              end
              else
              begin
                fIsX509 := true;
                xka := fX509.Signed.SubjectPublicKeyAlgorithm // more precise
              end;
            end 

#2 mORMot 2 » Create/sign jwt using Hardware Security Modules (HSM) usb token » 2026-06-05 13:31:20

ttomas
Replies: 2

Do we have all needed code to create/compute/sign jwt, using HSM. Any example?
I need RSA-SHA256 algorithm. TJwtRs256 use only file certificate!

#3 Re: mORMot 2 » How can I implement OAEP padding in RSA » 2026-05-09 10:55:36

I needed too. Just implement needed encryption/decryption, for similar Api, using openssl 3.
Small test in gist https://gist.github.com/TTomas/c65727c6 … 1ea9586df4
I have a problem in decrypt, function EVP_PKEY_CTX_set_rsa_oaep_md return error:03000094:digital envelope routines::invalid operation. Same function in encrypt is OK!
Workaround, I add EVP_PKEY_CTX_set_rsa_oaep_md_name in mormot.lib.openssl11.pas, diff in gist. In some forums, I find suggestion for openssl 3 to use this function.

#4 Re: mORMot 2 » PostgreSQL ORM behavior: Reusing deleted record IDs after insert » 2026-05-03 19:44:42

Yes if you restart service/application after delete. On start of your app, mormot ORM get max(ID) and keep ID in memory and increment before add new record.

#5 Re: mORMot 2 » mORMot + PostgreSQL: "lost synchronization with server" when switching » 2026-05-03 13:36:33

I just reproduce in Linux with 8 threads, need to click for a long time :-), and yes happen after Begin/End CurrentThread.

#6 Re: mORMot 2 » mORMot + PostgreSQL: "lost synchronization with server" when switching » 2026-05-03 13:14:19

@flydev, in you log did exception happen when TRestServerDB Begin/End CurrentThread happen? Or in @kabiri happen by chance.

#7 Re: mORMot 2 » mORMot + PostgreSQL: "lost synchronization with server" when switching » 2026-05-03 12:32:28

I can not reproduce you problem with source on post #60, with FPC, Ubuntu 24.04, mormot 2.4.14436!
If I view your log with SynLogView, filter only Trace, DB and one working thread 35, potentially is a bug in mormot when mormot.rest.sqlite3.TRestServerDB BeginCurrentThread/EndCurrentThread happen. It is hard to reproduce, you must start test, make pause and continue test and hit the time when Begin/EndCurentThread happen!
As@ab notice, to many Prepare in log, please set DBProps.UseCache := True;. Any reason for False?

#8 Re: mORMot 2 » mORMot + PostgreSQL: "lost synchronization with server" when switching » 2026-05-01 18:36:14

message type 0x31 arrived from server while idle
message type 0x32 arrived from server while idle
message type 0x54 arrived from server while idle
message type 0x44 arrived from server while idle
message type 0x43 arrived from server while idle
message type 0x5a arrived from server while idle
in Vi 260430200702 6658 confirm using same connection in multiple threads

#9 Re: mORMot 2 » mORMot + PostgreSQL: "lost synchronization with server" when switching » 2026-05-01 17:13:28

You must provide source of init of your server/services and code of your interface using orm/dbparams. For test, what type of http server you use sync/async and how many threads?
From log:
Vi 260430200213 6714 is main init thread all OK
Vi 260430200227 2c24, Vi 260430200228 3ad0 looks like working threads and all is OK, on top you have pg db connection
Vi 260430200601 5cc8 and Vi 260430200702 6658 threads don't have own connection and this is the problem, you use same db connection from different threads!
Look like interface created threads using db connection in wrong way, provide some source for ViTaskService.GetDetail, ViTaskService.ViewTask.
Or you call this methods from different thread!

#10 Re: mORMot 2 » mORMot + PostgreSQL: "lost synchronization with server" when switching » 2026-04-30 10:19:24

For testing, I will decrease http threads to 3-4, use mormot.db.sql.postgres.pas driver (smaller overhead compared to zeos), use tmThreadPool.
For logging use ptOneFilePerThread, for easy analyze the db log file.
  LogFamily := TSynLog.Family;
  LogFamily.Level := LOG_VERBOSE;
  LogFamily.PerThreadLog := ptOneFilePerThread;
You need small changes in mormot.db.sql.postgres.pas
TSqlDBPostgresConnection.Connect; already have logging
TSqlDBPostgresConnection.Disconnect; you need to add logging in finally block, log code like in Connect
TSqlDBPostgresStatement Prepare/ExecutePrepared already have logging
Start testing and after crash analyze the log

#11 Re: mORMot 2 » mORMot + PostgreSQL: "lost synchronization with server" when switching » 2026-04-29 13:34:33

Can you log thread/db connect/disconnect. Look like connect, prepare statement, execute prepared statement, disconnect (all OK). Then on next req you have connect, execute prepared statement from previous connection, without prepare statement.

#12 Re: mORMot 2 » mORMot + PostgreSQL: "lost synchronization with server" when switching » 2026-04-25 18:22:33

Why you use tmMainConnection? By default you have 32(you can change on creation of http server) http working threads and only one db connection (no db pool) in main thread. This working threads must wait from main thread to get/set data from single mainthread db connection.
If you use tmThreadPool, then all 32 working thread will create db connection and you will not have waiting/switch between threads for db connection. Yes some databases have problem with threading, but posgresql as I know don't have a problem.

#13 Re: mORMot 2 » mORMot + PostgreSQL: "lost synchronization with server" when switching » 2026-04-23 13:56:25

Kabiri wrote:

@ttomas : What exactly was your issue?

I don't use orm part and need to close db connection after interface use TSqlDBConnectionProperties.ThreadSafeConnection.Disconnect, without lock :-). I need my service to not use any db connection if users are out.
I just notice on slow req/rate useHttpSocket round robin all working threads, create connections on all threads. But async server create only one connection on first working thread. Http working thread=DB pool thread connection.

#14 Re: mORMot 2 » mORMot + PostgreSQL: "lost synchronization with server" when switching » 2026-04-23 11:23:21

What type of http server you use (TRestHttpServerUse)? I have a problem with useHttpAsync and FirebirdSql connection in interface service! Switching to useHttpSocket, problem disappear, different threading model. Problem was bug in my code, after bug resolve, both useHttpAsync and useHttpSocket are OK.

#15 Re: mORMot 2 » Setting Cookie in Response Header with RawJSON Output Not Working » 2026-03-31 13:09:53

You can try with
Ctxt.OutCookie['myCookie']:='MyValue';
also check httpServer.AccessControlAllowOrigin := ... if cross origin is involved
For cross origin cookie I use
Ctxt.OutCookie['refreshtoken']:=RefToken+'; SameSite=None; Secure; HttpOnly';

#16 Re: mORMot 2 » How To Make Special Query faster » 2025-12-31 15:11:57

Try to create table without index (primary key). After inserts, create index. Inserting in table with index is slower.

#17 Re: mORMot 2 » Trying to convert mORMot1 documentation conversion to mORMot2 » 2025-12-19 12:14:18

THttpAsyncClient doc, ex. Sample of using THttpAsyncClient in THttpAsyncServer service! Non blocking async service call remote service with async client.

#18 Re: mORMot 2 » many many same errors from tsynlog » 2025-11-17 19:57:32

Some external dll function raise exception! I notice similar log with Firebird Client fbclient.dll when disconnect, only on Win64. Win32 and Linux64 is OK, no exception!
As I investigate on net, there is some code in dll like:

try
  SomeFunc;
  result:=true;
except
  result:=false;
end;

#19 Re: mORMot 1 » Custom routing on method based service » 2025-09-24 14:22:39

In that case, best move your code to mormot2 and use new router, as @ab point.

#20 Re: mORMot 1 » Custom routing on method based service » 2025-09-24 13:13:55

g_garzotto wrote:

There is a simple way to add another model to the current server, in order to have some methods that use another routing ? For example:
http://ip:port/orders/myothermethod

Do you need another model in context of ORM or just another root uri for method based service?
If you need just another root, you can create TSQLRestServer inherited from TSQLRestServerFullMemory
TSQLRestServerOrders = class(TSQLRestServerFullMemory)
with constructor like

constructor TSQLRestServerOrders.Create(const aRoot: RawUTF8);
begin
  inherited CreateWithOwnModel([], false, aRoot);
end;
//... and change your code to
  FModel := TSQLModel.Create([], 'api');
  FService := TSSPOSRESTProcessor.Create(FModel);
  FOrders := TSQLRestServerOrders.Create('orders');
  FServer := TSQLHttpServer.Create(FPort, [FService, FOrders], '+', useHttpApiRegisteringURI);

#21 Re: mORMot 2 » Collate for case insensitive in Firebird » 2025-06-08 21:08:36

Firebird related question, check documentation. In short create field with collation, something like

CREATE TABLE PERSONS (
  PERS_ID INTEGER NOT NULL PRIMARY KEY,
  LAST_NAME VARCHAR(50) COLLATE UNICODE_CI,
  FIRST_NAME VARCHAR(50) COLLATE UNICODE_CI
);

More details at https://firebirdsql.org/file/documentat … types.html

#22 Re: mORMot 2 » Can someone help me figure out how to change the url for my endpoints » 2025-05-14 00:05:35

Typo missing / before root?
'/root/PerfilService.getperfilesusuario'
edited:
just tested work with and without '/', check some typo

#23 Re: mORMot 2 » Can someone help me figure out how to change the url for my endpoints » 2025-05-13 23:19:00

Do you try to rewrite GET to POST with urmPost?

Server.Route.Get('/Perfiles', 'root/PerfilService.getperfilesusuario', urmPost);

#24 Re: mORMot 2 » Question: Modifying OutCustomHeaders in GetViewInfo ? » 2025-03-20 22:05:51

For MVC app you can add parameter CustomOutHttpHeader to your public methods. @ab add this future when I need  response header for htmx application.

procedure TMyMVCApplication.Test(... , out CustomOutHttpHeader: RawUtf8); 
begin
  ...
  CustomOutHttpHeader := 'HX-Retarget: #dialog';
end;

#25 Re: mORMot 2 » High-Performance Frameworks » 2025-01-04 12:31:47

ab wrote:

The TFB program is compiled with FPC 3.2.3 so is not affected by those FPC trunk (temporary) issues - at least on my machine.

Inline function bug is affected in FPC 3.2
https://gitlab.com/freepascal.org/fpc/s … sues/41031

#26 Re: mORMot 2 » High-Performance Frameworks » 2025-01-02 09:04:30

pvn0 wrote:

Did it fail with libc mm or fpcx64mm?

-dFPC_LIBCMM -dFPC_LIBCMM_NOMSIZE

#27 Re: mORMot 2 » TSimpleHttpClient TWinHttp return empty Headers » 2025-01-01 19:56:44

Thanks @ab, problem solved.
Strange raw response with vscode including small body {"count": 8} is 2832 Bytes. But yes dwSize before QueryHeaders exec is 4108 and after is 5640 > 4KB

#28 mORMot 2 » TSimpleHttpClient TWinHttp return empty Headers » 2024-12-31 14:35:01

ttomas
Replies: 2

Some regression in last 5-6 month, today I update to trunk!
FPC/Win32/64, my client TSimpleHttpClient return empty headers string in response, response body is OK, valid json response, 200.
TCurlHttp is OK return headers, ReplaceMainHttpClass(TCurlHttp), but default TWinHttp is broken. TSimpleHttpClient.Headers

#29 Re: mORMot 2 » i have ian issue with concurrent calls to a function in SOA » 2024-10-28 12:01:20

Log shows you have 6 working threads, not 32! Execution time is >30sec, default timeout is 10sec if I remember.

#30 Re: PDF Engine » Acrobate reader close when try open an pdf file but open it in browser » 2024-10-24 22:49:57

Declared in SynCommons.pas, do you mix old and new pas files?

#32 Re: mORMot 2 » Help with SendEmail for Lazarus » 2024-09-12 13:07:56

Port 465 for SMTP with SSL/TLS encryption? Do you build same app bitness (32/64). Check your dll bitness if you use openssl.

#33 Re: mORMot 2 » Where do I start? » 2024-08-18 11:29:59

Better to create separate restserver for interface/methods with different root uri ex. api. Then you will have
/orm/Product for orm access and /api/Product for interface and method calls. In production when you put your service behind reverse proxy you will pass only /api uri, /orm access is not recommended for direct client access. You can still access /orm for some housekeeping on localhost.

#35 Re: mORMot 2 » Where do I start? » 2024-08-16 02:17:21

anouri wrote:

thanks. but yo write "TSQL*ConnectionProperties is connection pool, not real db connection! Real db connection is TSQL*ConnectionProperties"
it is same!
TSQL*ConnectionProperties = TSQL*ConnectionProperties

TSQL*ConnectionProperties.ThreadSafeConnection

#36 Re: mORMot 2 » Where do I start? » 2024-08-15 09:17:54

Yes it is right approach. Just note, TSQL*ConnectionProperties is connection pool, not real db connection! Real db connection is TSQL*ConnectionProperties.ThreadSafeConnection and is created for your running thread. This connection is keep open and reuse for every call in same thread, because db connect is time expensive. I you really need to close thread connection you can call TSQL*ConnectionProperties.EndCurrentThread at the end of your interface/method.

#37 Re: mORMot 2 » TSynDaemon Access violation on stop » 2024-06-24 22:06:08

Thanks @ab, problem solved with last changes, no more exception.
Problem is connected to firebird client lib, when aFbProps.Free; in Stop, (aFbProps: TSqlDBIbxConnectionProperties). When I remove aFbProps from app, no exception is raised!
Same code on Windows as console or service, or Linux console don't rise any exception, only as daemon forked/process.

#38 mORMot 2 » TSynDaemon Access violation on stop » 2024-06-24 11:31:51

ttomas
Replies: 3

Linux daemon raise exception on stop (systemctl stop ..)
EXCOS EAccessViolation (9df7d740) [Main] at 442bec ../../src/core/mormot.core.os.posix.inc  (3183)
./myapp --start # is OK
./myapp --stop # raise same exception
./myapp --c # console is OK

#39 Re: mORMot 2 » Json Serialize static array problem » 2024-06-18 14:09:14

Hafedh TRIMECHE wrote:

Please note that there is no Name field inside the TJsonRecord:

There is in your first post and also dynamic not static array, TBytes!

#40 Re: mORMot 2 » Json Serialize static array problem » 2024-06-17 18:41:04

You need to change record to packed record, also change Name type from string to RawUtf8 type.

#41 Re: mORMot 2 » How do I speed up initial access with external db to MS SQL » 2024-05-13 15:01:28

In your first log you have >3sec on connection, not on exec statement. First statement in thread must make connection 3sec,after that execution of statements is fast in same thread. Connection pool normal behavior

#42 Re: mORMot 2 » QuickJS und ServiceContainer » 2024-05-13 12:16:12

All main developers work together including @bellard and @chqrlie and plan to merge all changes in one repo.

#44 Re: mORMot 2 » QuickJS und ServiceContainer » 2024-05-07 14:04:06

Sorry Daniel, not a answer to your question, just use this topic for info of fork of quickjs where continue development of this lib.
https://github.com/quickjs-ng/quickjs
Some projects using quickjs switch to this fork. Any plan for mormot?

#45 Re: mORMot 2 » High-Performance Frameworks » 2024-04-24 11:05:31

Looking at Single query-Data table, async servers have worse result then ORM!
[async,nopin] mormot-postgres-async2 use 1 server, 56*2 threads (56*2-1=111 db connections)
all other tests use (56*(8-1)=392 db connections)
Not fair for  [async,nopin]!

Edited:
Looking at Data updates-Data table, for multiple updates 10,15,20, [async,nopin] benefit from lower db connections

#47 Re: mORMot 2 » Create SynCrossPlatform Wrapper with m2 broken » 2024-03-20 12:51:38

Comparing M1/M2 context, main deafferents is M2 have arrays, M1 don't have (in FPC).
And nestedRecord/Array is array of fields in M1, in M2 we have "fields" property as array of fields.
context.json M1 and M2 https://mega.nz/file/SbBUGaYQ#fwFb07BBX … qM4J3hyeU0
for sample https://synopse.info/forum/viewtopic.ph … 163#p41163

#48 Re: mORMot 2 » Create SynCrossPlatform Wrapper with m2 broken » 2024-03-20 11:26:01

Hi @itSDS,
0. Can you check/compare M1/M2 context.json, http://localhost:888/root/wrapper/context
1. Yes, depend of mustache template. I'm not sure that is possible correct order of types. I only look at SMS template to convert to pas2js template and in this template first is created all enums, then all record, then all arrays. Manuel modification is needed (reorder types) in created client.
2. Check 0. In M2 context we have all nested records/arrays as temporary type. This is needed for client that don't support nested types. Pas2js support nested records and arrays from some version, but don't support nested array of nested record and we need this temp types

// New Delphi/FPC version support
TPeople = packed record
  MyArr: array of record
                 name: RawUtf8;
               end;
end;
// in Pas2JS, must be transformed to
TTmp1 = record
  name: RawUtf8;
end;
TMyArr2 = array of TTmp1;
TPeople: TMyArr2;

This temp types also simplify code to all helper variant2* *2variant functions, if you use this types.
Some changes must be done in template if you don't need this temp types. Looking at context.json

					"nestedRecord": {
						"nestedRecord": null,
						"fields": [
							{
								"typeWrapper": "wRawUtf8",
								"typeSource": "RawUtf8",
								"typeDelphi": "RawUtf8",
								"typePascal": "String",
								"typeCS": "string",
								"typeJava": "String",
								"typeTS": "string",
								"typeSwagger": {
									"type": "string"
								},
								"propName": "Name",                 <---
								"fullPropName": "CatNested.Name",   <---
								"nestedIdentation": "  ",          
								"isSimple": true
							},

You can change in template fullPropName to propName, depend what you need to be generated.
I tested only on FPC and Pas2JS template. Delphi testing is needed and all clients templates.
It is good to add field isNested: true to all anonymous temp types to be able to create or not code for this types in template!

#49 Re: mORMot 2 » Create SynCrossPlatform Wrapper with m2 broken » 2024-03-19 20:56:32

Please try/test my fork mormot.soa.codegen.pas.  Pull request is 2 days ago, testing is welcome before merge.
https://github.com/TTomas/mORMot2/blob/ … odegen.pas
Discussed in topic https://synopse.info/forum/viewtopic.php?id=6375

#50 Re: mORMot 1 » TMS WebCore » 2024-03-17 14:42:14

@ab, I create pull request
@rdevine, I update pull request
This type of interface is tested

  TSex = (cMale, cFemale);

  TCat = packed record
    Name: RawUtf8;
    Sex: TSex;
    Birthday: TDateTime;
  end;

  TCatDynArray = array of TCat;
  TCat3Array = array[0..2] of TCat;

  TPeople = packed record
    FirstName: RawUtf8;
    LastName: RawUtf8;
    Sex: TSex;
    Birthday: TDateTime;
    Cat: TCat;
    CatNested: packed record
        Name: RawUtf8;
        Sex: TSex;
        Birthday: TDateTime;
      end;
    Cat3: TCat3Array;
    Cats: TCatDynArray;
    CatsNested: array of TCat;
  end;

  ICalculator = interface(IInvokable)
    ['{9A60C8ED-CEB2-4E09-87D4-4A16F496E5FE}']
    function Add(n1, n2: integer): integer;
    function ArrayValue(const arrJSON: RawUtf8; ix: integer): variant;
    function CountArray(const jsn: RawUtf8): integer;
    function SumArray(const jsn: RawUtf8): double;
    procedure FullName(const aFirstName, aLastName: RawUtf8;
      var aFullName: RawUtf8; var aSize: integer);
    function CatIsMale(const aCat: TCat): Boolean;
    function GetCat: TCat;
    function GetPeople(aId: integer; var aPeople: TPeople): Boolean;
    function AddPeople(const aPeople: TPeople): integer;
    function AddCat2People(const aCat: TCat; var aPeople: TPeople): boolean;
  end; 

With this changes created client need only 2 manual changes, move array types before TPeople record and Replace All nested type names with correct type name.
In https://github.com/TTomas/mORMot-Web/tr … Pas2JSTest you can view context.json and exported client mORMotPas2JsClientExport.pas and edited mORMotPas2JsClient.pas.
I try version without helper record/array function, In GetPeople onSuccess to use

      onSuccess(TPeople(res[0]),Boolean(res[1]));

For simple types we can use this casting, but Birthday TDateTime field will be corrupt in pas2js. After this type of casting this field is no longer TDateTime (double/Number) but String (mormot serialize as iso8601) and using any datetime function is broken. This is JS world!
Using helper functions everythig is OK. Template is modified SMS and still there is a lot of SMS code in template. Need more testing on different structures.
@ab we need correct type naming for temporary nested fields (CatNested/CatsNested).

Board footer

Powered by FluxBB