You are not logged in.
Tested on Windows 7, 10, 11 Pro, 11 Home, and 11 Pro ARM. We deployed an update to our main app with commit f674c4858 added, no complaints until now.
Problem solved.
Keep up the excellent work ab.
Ok. After adding some logging and stack tracing, and with some help from AI, this is what I found:
On the log file:
0000000000000d64 ! EXCOS EAccessViolation (c0000005 EXCEPTION_ACCESS_VIOLATION) [Main] at 02666302 mormot.rest.client.pas TRestClientAuthenticationDefault.ClientComputeSessionKey (1402) {2 0.24 0.68 0.9GB/6GB 1db10b01}
00000000000d455f ! ERROR ERROR: {"EAccessViolation(0d30dff0)":{Message:"Access violation at address 02666302 in module 'Horarios.exe' (offset 1606302). Read of address 0000000B"}} mormot.core.log.pas TSynLog.LogInternalFmt (6000) mormot.core.log.pas TSynLog.Log (5303) U_data.pas tTablesServer.user_loginOk (4121) U_login.pas TFRM_login.processLogin (357) U_login.pas TFRM_login.BUT_okClick (679) TControl.Click cxButtons.pas TcxCustomButton.MouseUp (2221) TControl.DoMouseUp TWinControl.WndProc TButtonControl.WndProc TWinControl.MainWndProc StdWndProc
00000000000d491f ! EXCOS EAccessViolation (c0000005 EXCEPTION_ACCESS_VIOLATION) [Main] at 02666302 mormot.rest.client.pas TRestClientAuthenticationDefault.ClientComputeSessionKey (1402) mormot.rest.client.pas TRestClientAuthentication.ClientSetUser (1331) mormot.rest.client.pas TRestClientUri.SetUser (2957) U_data.pas tTablesServer.user_loginOk (4116) U_login.pas TFRM_login.processLogin (357) U_login.pas TFRM_login.BUT_okClick (679) TControl.Click cxButtons.pas TcxCustomButton.MouseUp (2221) TControl.DoMouseUp TWinControl.WndProc TButtonControl.WndProc TWinControl.MainWndProc StdWndProc {2 0.24 0.68 0.9GB/6GB 1db10b01}Fix proposal / hint:
I highlighted the fix and the line where the error occurs with //########
class function TRestClientAuthenticationDefault.ClientComputeSessionKey(
Sender: TRestClientUri; User: TAuthUser): RawUtf8;
var
resp, mcfhash, servernonce, clientnonce, proof: RawUtf8;
clientsign: THash256;
rnd: THash128 absolute clientsign;
values: array[0..1] of TValuePUtf8Char;
begin
result := ''; // error
if User.LogonName = '' then
exit;
FillChar(values, SizeOf(values), 0); //######## FIX
// compute the 160-bit client nonce (needed by ScramClientProof)
Random128(@rnd); // unpredictable
Join([CardinalToHex(OSVersionInt32), '_', BinToHexLower(@rnd, SizeOf(rnd))],
clientnonce);
// try "mcf" for servers with "Modular Crypt" support
if (User.PasswordHashHexa <> '') and
(User.Data = 'mcf') then // passModularCrypt flag with clear/plain password
begin
User.Data := '';
Sender.CallBackGet('auth', ['username', User.LogonName, 'mcf', 1], resp);
JsonDecode(resp, ['result', 'mcf'], @values);
values[0].ToUtf8(servernonce);
if servernonce = '' then
exit;
// hash the password, with proper "Modular Crypt" support
if values[1].Text <> nil then // this user got a mcf specific format
mcfhash := ModularCryptHash(values[1].ToUtf8, User.PasswordHashHexa);
if mcfhash <> '' then
if values[1].Text^ = '$' then
// no mutual auth - regular mORMot 1 hashing
User.PasswordHashHexa := mcfhash
else
// SCRAM-like mutual authentication with irreversible proofs
proof := ScramClientProof(mcfhash, User.LogonName, clientsign,
// match ScramServerProof() msg parameters
[Sender.fModel.Root, servernonce, clientnonce, User.LogonName])
else
User.SetPassword(User.PasswordHashHexa, ''); // fallback to old hash
end
else
// regular authentication with User.PasswordHashHexa = hashed value
servernonce := Sender.CallBackGetResult('auth', ['username', User.LogonName]);
if servernonce = '' then
exit;
// compute and return a proof, challenged against client and server nonces
if proof = '' then
// regular mORMot 1 authentication via simple hexadecimal hashing
proof := Sha256U([Sender.fModel.Root, servernonce, clientnonce,
User.LogonName, User.PasswordHashHexa]);
result := ClientGetSessionKey(Sender, User, [
'username', User.LogonName,
'password', proof,
'clientnonce', clientnonce]);
// now result <> '' contains 'id-privatekey' on authentication success
if (values[1].Text <> nil) and //######## ERROR: EAccessViolation - depending on Optimization and Windows version
(values[1].Text^ = '#') then
// authenticate the SCRAM server from the returned proof
if result = '' then
User.PasswordHashHexa := ''
else if ScramClientServerAuth(mcfhash, User.LogonName,
Sender.fSession.ScramServerProof, clientsign) then
// success: fSession.PrivateKey computed without the server DB key
User.PasswordHashHexa := '#'
else
result := ''; // error
end;I found that the Access violation on mORMot 2.4 actually happened on more windows versions (Windows 7, Windows 10 and Windows 11 ARM) depending on the Optimization being on or off.
On some windows versions it happens when Optimization is on, on others when it is off...
After a couple hours of not being able to do remote debugging on the specific application/system where the error happens (I can do remote debugging on a simple app, but not on our main app, I don't know why) I turned to rudimental debugging mode (using showMessage('test 01') on suspicious lines to try to pinpoint the line where the error happens lool. Yeah, I know...
But I did eventually found something that I think maybe is a clue for you guys to fix the root cause of this strange problem.
I added "Application.processMessages" to mORMot's ClientSetUser function and this fixes the problem in almost every windows version, unfortunately, with this line added the error started to happen on some Windows 11 x64 machines... So... not a 100% fix. We did end up removing this fix because we cannot predict the machines it will affect, and there are far more Windows 11 x64 machines then older Windows versions on our client base.
Adding "Application.processMessages" would never be a final fix of course.
I was using showMessage to find the line where the error happens... But I noticed that using showMessage in certain places caused the error not to happen...
I then used Application.processMessages insted of showMessage for a silent solution...
I'm available to test on my specific app if there is something to this and you need some testers.
While trying to set up remote debugging, I disabled Optimization in the project options - Building > Delphi Compiler > Compiling, and now the application works without any issues on Windows 10.
Very strange.
Today we deployed an update to our client application, which uses mORMot v2.4.
Several Windows 10 users reported an Access Violation error (the typical "Access violation at address aaaaaa in module bbbbb (offset cccccc). Read of address dddddd.").
I reproduced the issue on a Windows 10 VM. I also tested the application after reverting to mORMot v2.3, and the error no longer occurs with that version.
On Windows 7 and Windows 11, the application works without any issues.
Unfortunately, I don't have access to a Windows 10 dev machine to debug this further.
With the current trunk i'm getting an error because LockedSessionDelete no longer exists.
I have a procedure to kill sessions with the following code:
procedure TDCS_ServerDB.sessions_kill(Ctxt: TSQLRestServerURIContext; arrSessions_kill: tArrayOfInt64);
var
i, i2: int64;
countDel: integer;
currSession: TAuthSession;
begin
countDel := 0;
if (self = nil) or (fSessions = nil) or (fSessions.Count = 0)
then exit;
fSessions.Safe.ReadWriteLock; // won't block the ReadOnlyLock methods
try
for i := fSessions.Count - 1 downto 0 do
begin
currSession := self.fSessions[i];
for i2 := 0 to High(arrSessions_kill) do
if currSession.ID = arrSessions_kill[i2] then
begin
if countDel = 0 then fSessions.Safe.WriteLock; // upgrade the lock (seldom)
LockedSessionDelete(i, nil);
inc(countDel);
end;
end;
finally
if countDel <> 0 then
fSessions.Safe.WriteUnlock;
fSessions.Safe.ReadWriteUnLock;
end;
end;LockedSessionDelete does not exist now.
Maybe there is some other way to do the same thing?
Thank you.
Appreciate it, @rvk. That’s what I had in mind. I usually refer to it as 'master' or 'main', my bad.
Sorry, how do I get that trunk?
I was getting the same problem when compiling our server application targeting 64bit.
I switch to "lts-2.3" and now it compiles fine.
But I'm getting 75.807 assertion failures when running mormot2tests:
1.7. Network protocols:
- DNS and LDAP: 3 / 1,593 FAILED 90.32ms
2.2. Sqlite file:
- TRestClientDB: 18,951 / 398,577 FAILED 653.65ms
2.3. Sqlite file WAL:
- TRestClientDB: 18,951 / 398,577 FAILED 671.65ms
2.4. Sqlite file memory map:
- TRestClientDB: 18,951 / 398,575 FAILED 618.40ms
2.5. Sqlite memory:
- TRestClientDB: 18,951 / 466,885 FAILED 762.23ms
So...Yeah. I'm missing something obvious for sure...
Hello, sorry for the late reply. The problem is solved.
Once again, thank you.
Hello and thank you once again for your prompt reply @ab.
We do not use Allow/Deny of group por service.. All groups have full access to all services.
We use groups to separate out clients, each client has its own group, the users of each group share session data when they are logged in.
I don’t know if that is the best approach, but it has been working great for us so far.
Hello,
We updated to mORMot v2 recently, very smooth transition so far.
Today, when deploying our first server using version 2 we started having this error saying "Unauthorized method" on every interface method call. After some debugging I found this code:
unit mormot.rest.server;
(...)
procedure TRestServerUriContext.InternalExecuteSoaByInterfaceComputeResult;
(...)
if (Session > CONST_AUTHENTICATION_NOT_USED) and
(ServiceExecution <> nil) and
((SessionGroup <= 0) or
(SessionGroup > 255) or
(byte(SessionGroup - 1) in ServiceExecution.Denied)) then
begin
Error('Unauthorized method', HTTP_NOTALLOWED);
exit;
end;Looks like I will get an error if I have more then 255 Groups (more precisely if I have Groups with ID greater then 255).
Is this by design?
I changed the 255 to 2000 to patch my server and it seems to work ok, but I don't know if this causes adverse side effects... I would remove the SessionGroup > 255 condition if possible...
Our use case requires lots of user groups, more than a thousand...
Please advise.
Thank you!
Ok, thank you!
The problem is solved, no more errors while debugging.
Is it safe to use this commit (e8293e7) in production?
Thank you once again Arnaud
I will try that commit and let you know.
It is a small annoying thing (it disrupts the debug a little) but it does not affect anything as far as I'm aware.
Side note: on mORMot 1 that didn't happen. Same server configuration (useHttpApiRegisteringURI).
I'm just creating it like that:
MSS_ServerDB.DB.Synchronous := smOff;
MSS_ServerDB.DB.LockingMode := lmExclusive;
TRestHttpServer.Create(K_conn_port_cloud, [MSS_ServerDB], '+', useHttpApiRegisteringURI, 32, secSSL, '', '')
If that's not the best way to create the server please advise...
I'm using the TRestHttpServer class to expose a TRestServerDB server (more precisely, a class that extends the TRestServerDB with some server methods, and some helper methods as well.. nothing too fancy).
Yes, on production there is no error.
Our TAuthGroup.SessionTimeout is 60.
But I get those errors after way less the 30 minutes of inactivity...
In this next case, only 7 minutes have passed:

I think there is something else going on...
When my app is not doing nothing I still get those errors, it could confirm this time dependent theory.
Erro and Call Stack:


Hello,
Using the commit above I get:



If I open and close the app rapidly I get no error... Seems to be time dependent, but I could be wong.
No, the server is a separate program altogether.
I can add the Call Stack if that helps...
I frequently have this error, only on debug (Delphi 12).
Error:
Project xpto.exe raised exception class ENetSock with message 'THttpClientSocket.SockSendFlush(127.0.0.1) len=292 [Fatal Error - #6]'
It doesn't happen every time and not in the same place (in the code)... It appears to be harmless.
I added the IRestOrm thing. This is a non critical part of the client code so I will let it stay this way (and it is working).
Thank you!
It is working now... Thank you ab.
Please just confirm that this is correct...
procedure TForm1.Button1Click(Sender: TObject);
var
MSC_mem: TRestServerFullMemory;
MSR_table: TOrmUser;
begin
MSC_mem := TRestServerFullMemory.CreateWithOwnModel([TOrmUser]);
MSR_table := TOrmUser.Create;
MSR_table.FillPrepare(MSC_mem.Orm, '');
// Add a Record
MSR_table.ClearProperties;
MSR_table.SetFieldVariant('Name', 'Paula');
MSR_table.SetFieldVariant('Age', 48);
MSC_mem.Add(MSR_table, true);
// Add another Record
MSR_table.ClearProperties;
MSR_table.SetFieldVariant('Name', 'Maria');
MSR_table.SetFieldVariant('Age', 48);
MSC_mem.Add(MSR_table, true);
// Save JSON
MSR_table.FillPrepare(MSC_mem.Orm, '');
Memo1.Lines.Text := MSR_table.FillTable.GetJSONValues(true);
MSR_table.Free;
MSC_mem.Free;
end;Hello!
The code below works on mORMot 1 but not on version 2...
procedure TForm1.Button1Click(Sender: TObject);
var
MSC_mem: TRestStorageInMemory;
MSR_table: TOrmUser;
begin
MSC_mem := TRestStorageInMemory.Create(TOrmUser, nil, '');
MSR_table := TOrmUser.Create;
MSR_table.FillPrepare(MSC_mem, '');
// Add a Record
MSR_table.SetFieldVariant('Name', 'Paula');
MSR_table.SetFieldVariant('Age', 48);
MSC_mem.Add(MSR_table, true, false, false);
// Save JSON
MSR_table.FillPrepare(MSC_mem, '');
Memo1.Lines.Text := MSR_table.FillTable.GetJSONValues(true);
MSC_mem.Free;
end;I get an error on line: MSC_mem.Add(MSR_table, true, false, false);
(Access violation error)
What is the problem?
I will use this to convert some data to JSON, multiple records.
Thank you.
Thanks igors233, now I can move on ![]()
Hello.. I still can't find the NamedPipe server, can someone please point me in the right direction or confirm it is not available anymore?
Thank you.
Thank you for this, it is working.
I did miss another thing... The NamedPipe server... It is not available anymore?
Same question here...
Did you found a solution AntonE?
Hello,
I need some help, probably something very basic...
I'm currently refactoring our code to use mORMot version 2 and I can't find the function CurrentServiceContext (previously found on the mORMot.pas unit) to get the TServiceRunningContext.
Thank you.
I will do these changes and use TSQLHttpClient (TSQLHttpClientWinHTTP), correct?
Thank you for your help.
The socket client ( TSQLHttpClientWinSock ? ) doesn't support SSL if I remember correctly...
We din't migrate to mORMot 2 yet...
Thank you ab..
I think some clients use a proxy, but the majority don't...
Some clients report problems when using their home internet provider also (very simple direct PC-Router connection with no proxy)...
We use TSQLHttpClient (TSQLHttpClientWinHTTP) and TSQLRestClientURINamedPipe.
The change between local/cloud uses TSQLRestClientRedirect.
The issues only happen when TSQLRestClientRedirect is Redirect To TSQLHttpClient.
Hello everyone,
Our application has been experiencing some connection issues lately. And we are having a hard time figuring out why...
It doesn't happen on our headquarter's computers at all (Win10 and Win11), it happens on the clients, but not always, they will have trouble connecting (or requests fail mid-session) randomly.
When a request fails we find two different errors (with the same error code):
- winhttp.dll error 12019 (The handle is in the wrong state for the requested operation)
- winhttp.dll error 12019 (00002EF3)
It doesn't help the fact we can't debug this because we are not having the issue on our computers, and we never know on what client's computer it will happen...
We now have a dedicated server on a hosting company running the server application, before that, we used a VPS on another hosting company, and the issues persisted on this brand new dedicated server with new config, new SSL certificate, new domain, and IP.
I did find this topic: https://synopse.info/forum/viewtopic.php?id=5550
In our case the issue is intermittent, I guess it rules out the Proxy configuration.
We don't have the {$R Vista.res} resource on our .dpr project files, can this be it?
We are at a loss here...
Ok... I confirm the OnAuthentificationFailed event is firing when the user enters wrong credentials and when a request is made after the session expired on the server.
It's doing what it is supposed, my bad...
Thank you for your help igors233 ![]()
Thank you igors233...
Is that not equal to implement the OnAuthentificationFailed event available on TSQLHttpClient?
When I tried that, OnAuthentificationFailed only fired when wrong credentials are inserted...
Hello everyone,
We are experiencing a problem regarding sessions (not mORMot's fault). We are using sicPerGroup instance life time.
It has to do with the way users use the software...
Some users (lots of them) let the client app (delphi) open all day, for quick access or something like that. When they let the computer hibernate, if 1 hour is passed (our session timeout), because the client app stops sending keep alive calls, the session is terminated by the server. When the client app tries to communicate with the server after that, it get's an error as expected.
Is there a way to re-connect (creating a new session), in such cases? Ideally the new login would be executed before the new request is sent, to avoid having to re-send that request after the new login is made.
I tried some events from TSQLHttpClient, OnFailed and OnAuthentificationFailed... but they do not seem to fire on http calls...
We are still on version 1... We will migrate to version 2 soon.
Thank you.
Hello! I did a reindex directly on the server and that solved all the issues I was having.
In Portugal we have all kinds of special characters and accents, and it seems TSQLRecordCaseSensitive does not support these.
I would prefer to have full compatibility with SQLite Studio, but I'm guessing it will not be possible. I was able to use SynDBExplorer and it works OK. It is not as polished as SQLite Studio of course.
Thank you very much for the replies, people in this forum are awesome.
Hello!
I'm experiencing a very strange problem..
First I started noticing that I was getting some extra results that shouldn't be on a particular table, they where deleted some time ago.
I did a Vacuum on SQLiteStudio, but the problem persisted. Then I did a Reindex (also on SQLiteStudio), the particular query started returning the correct results on SQLiteStudio but now, that same query returns no results using the ExecuteList function.
Then, when I add new records to that table I will get some results via mORMot (ExecuteList) and others on SQLiteStudio, both start missing some records... Very strange!
Is there any incompatibility when Reindex is ran?
Is there a way to do a reindex directly on the server using mORMot? (Ideally without stopping the server...)
Thank you!
This is all implemented now and working as we want, nice!
Thank you ![]()
For other people that may need something like this:
procedure TDCS_ServerDB.kill_otherGroupSessions(Ctxt: TSQLRestServerURIContext);
var
i: integer;
currSession: TAuthSession;
begin
self.fSessions.Safe.Lock;
for i := self.fSessions.Count - 1 downto 0 do
begin
currSession := (self.fSessions[i] as TAuthSession);
if (currSession.GroupID = Ctxt.SessionGroup) and
(currSession.IDCardinal <> Ctxt.Session) then
self.SessionDelete(i, Ctxt);
end;
self.fSessions.Safe.UnLock;
end;I think this is OK. Any suggestions ab?
Thank you for prompt help.
Ok, I think that's TSQLRestServer.fSessions.Safe.Lock / TSQLRestServer.fSessions.Safe.Unlock
![]()
Let's hope I don't need any additional help, Thank you.
Yes, that's right. But there is no Lock method on fSessions[] that I can find.
I'm inheriting my own TSQLRestServer class, I can call SessionDelete now like advised on this topic, but I can't call/find TSQLRestServer.fSessions.Lock.
Thank you!
SessionDelete is not public... I was trying to do this from an interface (TInjectableObjectRest), using self.Server
Hello!
I need to kill sessions from a specific user group on the server... Is this possible?
Thank you!
You're right, I found it mentioned.
Is there any way to execute a query without any conversion?
Hello!
I'm using direct SQL execution to do some tasks. Today I encountered a problem that seems to be a Bug, but need your opinion/confirmation.
I'm using firebird. I debugged the code and my suspect is the TSQLRestStorageExternal.AdaptSQLForEngineList function.
The SQL gets cutted in this example:
Input SQL: SELECT codigo FROM rec_prf WHERE (nome='' OR nome IS NULL) AND EscolaID='Example'
Output SQL: select Codigo from rec_prf where (Nome='' or Nome is nullIf no parentheses are used it works as expected.
No problem, repository created.