#1 2023-03-07 19:31:26

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

exception when the URL does not have the method

I have a mormot 2.1 server and I am calling methods from an interface

Using postman I call the url with just the name of the URL and without the method
ex The complete URL is  http://127.0.0.1:10000/pchr/v8/Restinf/method
where iRestinf is the interface and method is the interface method
when calling then URL http://127.0.0.1:10000/pchr/v8/Restinf/ without the method, I am getting an exception both in Delphi debug mode in mormot.rest.server line 3026
The same code with FPC in linux returns :

<body style="font-family:verdana">
	<h1>mORMot2 (Linux) Server Error 500</h1>
	<hr>
	<p>HTTP 500 Internal Server Error<p>EFastReader: Reached End of Input<p><small>mORMot 2

Offline

#2 2023-03-07 19:48:36

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,726
Website

Re: exception when the URL does not have the method

With a HTTP GET in postman?

On my side I got an error 400 as expected...

Offline

#3 2023-03-07 19:56:46

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception when the URL does not have the method

No, with a POST
I believe the problem is because I am using a slash / inside the base URI 'pchr/v8'

Last edited by dcoun (2023-03-07 19:59:36)

Offline

#4 2023-03-07 20:03:55

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception when the URL does not have the method

20013718  $  -    08.991.005
20230307 20013718  $ ret   	mormot.rest.server.TRestServerRoutingRest(05404860) {  "errorCode":500,  "error":  {"EOrmException":  {   "ClassName": "EOrmException",   "Address": "cb791a mormot.rest.server.pas TRestServerUriContext.ExecuteCommand (3029)",   "Message": "Unexpected Command=0 in TRestServerRoutingRest.Execute"  }}  }
20230307 20013718  $ srvr  	  ? POST pchr/v8/restInf=500 out=250 B in 8.99s
20230307 20013718  $ debug 	mormot.rest.memserver.TRestServerFullMemory(052f90c0) TRestServerRoutingRest.Error: {  "errorCode":500,  "error":  {"EOrmException":  {   "ClassName": "EOrmException",   "Address": "cb791a mormot.rest.server.pas TRestServerUriContext.ExecuteCommand (3029)",   "Message": "Unexpected Command=0 in TRestServerRoutingRest.Execute"  }}  }
20230307 20013718  $ EXC   	EOrmException {Message:"Unexpected Command=0 in TRestServerRoutingRest.Execute"} [R1 pchrv7 pchrv8] at cb791a mormot.rest.server.pas TRestServerUriContext.ExecuteCommand (3029)  
20230307 20012819  $  +    mormot.rest.memserver.TRestServerFullMemory(052f90c0).URI POST pchr/v8/restInf in=0 B
20230307 20002920  $  -    14.477.594

Offline

#5 2023-03-07 20:08:09

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,726
Website

Re: exception when the URL does not have the method

A slash within a TOrmModel.Root has never been supported nor tested.

Use route rewriting at HTTP server level to customize the input URI.

Offline

#6 2023-03-07 20:12:57

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception when the URL does not have the method

So, it is supported only for client side as mentioned in https://synopse.info/forum/viewtopic.php?id=6338 (first response) ?

Last edited by dcoun (2023-03-07 20:13:16)

Offline

#7 2023-03-07 20:28:20

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception when the URL does not have the method

I think also, that this is the problem for this too: https://synopse.info/forum/viewtopic.php?id=6491

Offline

#8 2023-03-07 21:01:44

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception when the URL does not have the method

Problem exists even with TOrmModel.Root that does not have a slash
Is only one interface allowed per TRestServerFullMemory ? because, I usually have at least two

Offline

#9 2023-03-07 21:02:22

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,726
Website

Re: exception when the URL does not have the method

Perhaps the error returned after https://github.com/synopse/mORMot2/commit/4ef093bd is more explicit.

You can write as many interface as you want in a single TRestServer.

Perhaps there is a problem with the fact that you have two TRestServer in your HTTP server, and that they have '/' in their Model.Root.

Offline

#10 2023-03-07 21:27:49

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception when the URL does not have the method

it does not compile with PUREMORMOT2, but at least, it works
Thank you a lot @ab

Offline

#11 2023-03-07 22:07:10

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception when the URL does not have the method

the problem here: https://synopse.info/forum/viewtopic.php?id=6491 is not fixed. it is now returning a 400 error
Removing the slash from Tmodel.root did not help, nor anything else.
I have now an other method in the other interface that does not work if compiled with FPC. If compiled with Delphi 11.2, it works without any problem
This method can be just a result assignment to return a result through TServiceCustomAnswer but it stills gives an 500 http error.
I am using Lazarus 2.2.5 (rev lazarus_2_2_4-27-g75ee8b4c01) FPC 3.2.3 x86_64-win64-win32/win64 and cross compiling for Linux but no success with fpc.

Offline

#12 2023-03-07 22:25:38

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,726
Website

Re: exception when the URL does not have the method

I am not able to reproduce your problem.
It is possible there is something outside mORMot, e.g. in your code, which triggers some memory corruption.

I just run all mormot tests with FastMM4 in FullDebugMode with no issue reported.
Do the same for your own code.

Offline

#13 2023-03-07 23:09:05

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception when the URL does not have the method

I will try it in windows with FPC, as with Delphi it works OK
But I am not sure it is from my code. I do not have many methods and everything else worked for months till now, without even a restart.
The same interface has an other method with exactly the same code as the problematic method. The only difference is a RetrieveDocVariantArray that uses a different Torm table. No other difference.
both search a different table with the same parameters and return the query results.
I changed in the "working" method the Tormtable used in the query and I got the same problem. I finally succeeded to have the problematic method to work by just removing a search Tdatetime parameter in the query that usually causes the result to be an empty query.
Now it works. I will check it again tomorrow.

Offline

#14 2023-03-08 07:32:33

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,726
Website

Re: exception when the URL does not have the method

If you can write a https://stackoverflow.com/help/minimal- … le-example or debug on your side the non working method to see what is wrong...

For FPC/Lazarus, use the fpdebug debugger which is much more stable and usable that gdb.

Offline

#15 2023-03-09 23:37:12

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception when the URL does not have the method

I was travelling and it was not possible to debug it since now. In win64 target, there is no exception. in Linux 64, it happens when the resulted query from RetrieveDocVariantArray  is empty.
I will try to debug it more tomorrow.

Offline

#16 2023-03-10 11:24:39

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception when the URL does not have the method

I have installed wsl2, ubuntu and I was able to have the exeception in this enviroment.
I installed the FPC for linux to be able to trace it and I found that the exception happens in mormot.soa.server line 1510  when calling

WR.SetText(Ctxt.Call.OutBody);

and especially, in mormot.core.base, line 11548,

FastAssignUtf8(Text, fDataString) // FPC expects this  

As far as I can see Text is zero length empty string and FDataString has a value of '[]'.

My method is:

function TinterP.GetOrders(const sdat, edat: rawutf8; const pid: int64): TServiceCustomAnswer;
var ..... sdat_,edat_:RawUtf8; _pid:Int64; v:variant; p:Tid;
begin ..... p:=0; ......
v:=MyTrestserverDB.Orm.RetrieveDocVariantArray(Tormmyorm,'aa','pid=? and sdat>=? AND edat2<=?',[_pid,sdat_,edat_],'RowID,edat,sdat,extra,lastupd',@p);
if p=0 then result:=prepSCA(204,'[]') else result:=prepSCA(200,VariantToUtf8(v.aa)); 
end;

prepSCA is just a function to return a TServiceCustomAnswer with the arguments.

If the query has results everything is OK. If it is empty an exception happens, only in linux
I am using Lazarus 2.2.7 (rev ada7a90f86) FPC 3.2.3 x86_64-linux-gtk2

Last edited by dcoun (2023-03-10 11:51:54)

Offline

#17 2023-03-10 11:58:42

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception when the URL does not have the method

I have tested the function leaving just the if clause and the same happens.
I start the service connecting to a postgres db and this is the first call

Offline

#18 2023-03-10 13:21:53

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,726
Website

Re: exception when the URL does not have the method

IMHO you should not use RetrieveDocVariantArray but directly the JSON from the DB.

But anyway, please try if https://github.com/synopse/mORMot2/commit/2c2a774b makes a difference.

Offline

#19 2023-03-10 16:57:07

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception when the URL does not have the method

It started as a copy-paste function. You have right, now I learn from RetrieveDocVariantArray's code, I will change it.

Concerning the problem in this tread, it works now OK and the problem described here https://synopse.info/forum/viewtopic.php?id=6491 is also fixed.
Thank you a lot @ab

Offline

#20 2023-03-13 09:54:29

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,726
Website

Re: exception when the URL does not have the method

The https://github.com/synopse/mORMot2/commit/2c2a774 fix introduced a regression, in multi-thread context.
I was able to reproduce the problem with the multi-thread tests, and enabling verbose logs, so that process could be a little bit delayed, and multi-thread TRawByteStringStream reuse triggered some unexpected wrong results, due to fDataString string reuse and in-place overwrite. In short, the string returned by the server was not the one processed on the client, because it had sometimes been reused and rewritten for another request in another thread in-between.

Should be properly working now with https://github.com/synopse/mORMot2/commit/8d3dc2b2

I bless our aggressive regression tests to be able to reproduce such issues, and the verbose logs to make the root cause obvious: on production, it could have been awful to debug!

Offline

#21 2023-03-14 07:25:27

dcoun
Member
From: Crete, Greece
Registered: 2020-02-18
Posts: 430

Re: exception when the URL does not have the method

Thank you @ab for your time and your amazing work.

Offline

Board footer

Powered by FluxBB