#1 Re: mORMot 1 » Access violation after the latest commit » 2023-01-03 02:57:10

ab wrote:

DynArrayLoadJson / DynArraySaveJson work with no problem on my side.
Please provide us with some code to reproduce the problem.

When I begin to play with mORMot 'DynArrayLoadJson' was not working properly, but today I could make it work. I refactored the type used from:

TMyArray = array of packed record
                    ...
                    end;

TMyEntity = packed record
                     MyArray : TMyArray;
                   end; 

To:

TMyData  = packed record
                  ...
                  end;
TMyArray = array of TMyData; 

  Now, I can read/write the JSON data with "DynArrayLoadJson / DynArraySaveJson" the same way that my "wrong" code did, but I am still getting AV when closing the test application. I am still checking what is causing that. Thanks!

  PS: The 'AV' occurs only inside Delphi. I still need to try FastMM4 like you suggested

#2 Re: mORMot 1 » Access violation after the latest commit » 2023-01-02 01:36:11

tbo wrote:

I wish everyone a happy new year.
Sorry for my ignorance. But I don't know how to load an array of records with function RecordLoadJson. I don't remember being able to call this function other than with TypeInfo.Kind is Record. I can trigger an access violation with the following source code:

Thomas, since I discovered the outstanding mORMot framework almost three years ago, I realized I should start using it deeply in my projects, but it requires some education to begin playing with it. For the project in question, and as I am still learning mORMot, I created a testing environment application where I also learn mORMot fundamentals, and then next I use what is mature in the real projects. I was never happy with the fact that when serializing/unserializing JSON I was not using the right counterpart function, as I had tested the right pair or functions (like 'DynArrayLoadJson / DynArraySaveJson', 'RecordLoadJson / RecordSaveJson') and it never worked as I was expecting, probably due something I was doing wrong. I never felt well when I was mixing those previous functions to read/write JSON. The main JSON I have to deal with I defined like this:

TMyArray = array of packed record
                           ...
                           end;

TMyEntity = packed record
                     MyArray : TMyArray;
                   end; 

The "combination" that worked, in this case, was something like this:

When reading:

var TempRec : TMyEntity;

RecordLoadJson(TempRec, my_json TypeInfo(TMyEntity));

When writing:

var tmp : RawJson;

tmp := DynArraySaveJson(MyEntity.MyArray, TypeInfo(TMyArray), false);

I never make that work if I had used the pair "DynArrayLoadJson / DynArraySaveJson". This has been working since March/2022. No "access violation" until some weeks ago, then AV for the writing part, and after the last commit it came back to normal (ALL that without any change in my code), but now I got an AV in a unit that I don't use at all.

You said that you don't know how to load an array of records with 'RecordLoadJson'. The way I did above allow me to do it, although that would sound weird because 'RecordLoadJson' is used to load a 'TMyEntity' (that is a record of an array of record), I guess the whole bunch of JSON records are treated as a big JSON, but I am not sure. I would like to simply use 'DynArrayLoadJson / DynArraySaveJson' for that, but I never knew how to do it.

#3 Re: mORMot 1 » Access violation after the latest commit » 2023-01-01 17:02:37

Thanks, ab and mpv, I'll try to follow your tips and see what I can find. Mpv, some of the symptoms you described in the post mentioned I can see too. Those 'ghost' AVs are not easy to find, but I'll keep chasing them.

#4 Re: mORMot 1 » Access violation after the latest commit » 2022-12-31 21:43:20

I hope everybody has a Happy New Year!


Let's do a simple chronology of what has happened so far, using Delphi 11.2:

1) My test environment has been working well since March/2022, in this case, using only three mORMot objects/functions: 'TSimpleHttpClient', 'RecordLoadJson', and 'DynArraySaveJson';

2) After the commit right before my first message (or the previous one) on this thread, without changing anything in my code, I began to get an "access violation" error according to what was described above;

3) After the latest commit I got today, the "access violation" is gone. I thought something at 'mormot.core.json' could be the cause of the access violation, but I checked all the latest changes on that unit and found nothing relevant that could lead to that error;

4) Now when I close my test application I get another "access violation" error, now at 'mormot.core.base', precisely on this procedure, line 7086:

procedure ObjArrayClear(var aObjArray);
var
  a: TObjectDynArray absolute aObjArray;
begin
  if a = nil then
    exit;
  // release all owned TObject instances
  RawObjectsClear(pointer(aObjArray), PDALen(PAnsiChar(a) - _DALEN)^ + _DAOFF);      <--- The "access violation" is here
  // release the dynamic array itself
  a := nil;
end;

5) I debugged all my 'finalization' sections (I don't have any 'OnClose/OnDestroy' events in my test application) and all then are clear, no error at all;

6) I personally don't use any function/procedure of 'mormot.core.base'. It is listed in my uses clause just because I use 'RawUtf8' variables and that type is defined there;

7) It looks like some side effect is taking place in my case, but I don't think it is easily reproducible in a 'test case'. As I said, I only use those three 'object/functions' from mORMot in this test application. I really don't know why that function is been called at the end of the application, but it has anything to do with my code.

8) For sure there is a hidden "bug" somewhere in mORMot, and if I have a clue where it is I'll post it here.

#5 Re: mORMot 1 » Access violation after the latest commit » 2022-12-30 14:31:25

Thomas, thanks again for your input.

I am still investigating what has changed, as I told you in the first message, nothing was changed in the code from my side. The error that I got is "access violation", typical of accessing an area of memory not previously reserved, but now the error is been raised with the same data that some days ago was working ok. If I found something new, I'll post it here.

#6 Re: mORMot 1 » Access violation after the latest commit » 2022-12-29 14:50:29

It is like

MyTypeArray = array of packed record
                                               ...
                                              end;

I read a huge JSON that I receive from a REST service and load it using 'RecordLoadJson' without trouble. At some point in my test environment, I need to save the final JSON and it is when I use 'tmp := DynArraySaveJson(MyData, TypeInfo(MyTypeArray), false);'. It was working great until some days ago. Now it raises that "access violation error".

#7 Re: mORMot 1 » Access violation after the latest commit » 2022-12-29 04:25:22

Hello Thomas,

Thanks for your help. However, right now I am unable to produce a sample to test the problem. I have a lack of time due to the kind of analysis I have to do with the data read through mORMot JSON routines. It is a huge set of data, and it is really time-consuming. I was talking about the concrete case that my test application was not raising an error when I was using:

tmp := DynArraySaveJson(MyData, TypeInfo(MyTypeArray), false);

I changed nothing in my code but the "access violation" error started after the latest or previous commit. Looking a little further, I realized that the error occurs at the following looping:

mormot.core.json - line 5330

repeat
        jsonsave(P, c);  <-- The error occurs here
        dec(n);
        if n = 0 then
          break;
        c.W.BlockAfterItem(c.Options);
        inc(P, s);
      until false;

I am trying to get the previous commits and compare them to see what could have changed.

#8 mORMot 1 » Access violation after the latest commit » 2022-12-28 16:15:15

Prometeus
Replies: 17

In a project that was working normally until the latest commit, now I got the error "Project X raised exception class $C0000005 with message 'access violation at 0x00301608: read of address 0x1c43ef44"

The error happens when I use 'DynArraySaveJson'. It seems to be here:


mormot.core.json -- line 5501

if isHumanReadable in flags then
            c.W.WriteObjectPropNameHumanReadable(pointer(p^.Name), length(p^.Name))
          else
            c.W.AddProp(pointer(p^.Name), length(p^.Name));                                               <-- The error is here

#9 Re: mORMot 1 » Error when compiling the latest github update » 2022-10-26 12:05:23

My intention was just to help in the process as a whole

Thanks

#11 mORMot 1 » Error when compiling the latest github update » 2022-10-26 10:27:25

Prometeus
Replies: 3

I am receiving the following errors when compiling the latest update on Delphi 11.2:

[dcc32 Error] mormot.lib.winhttp.pas(2103): E2003 Undeclared identifier: 'SysErrorMessagePerModule'
[dcc32 Error] mormot.lib.winhttp.pas(2264): E2003 Undeclared identifier: 'SysErrorMessagePerModule'
[dcc32 Error] mormot.lib.winhttp.pas(2435): E2003 Undeclared identifier: 'SysErrorMessagePerModule'
[dcc32 Error] mormot.lib.winhttp.pas(2611): E2003 Undeclared identifier: 'SysErrorMessagePerModule'

#12 Re: mORMot 1 » A small example in response to a question » 2022-07-30 11:31:02

One more great contribution!

Thanks, Thomas!

#13 Re: mORMot 1 » Implementing OAuth2 » 2022-07-28 21:35:33

ab wrote:

Perhaps a new public gist may be more convenient.

..

The file is not mine, so I don't feel comfortable doing this

#15 Re: mORMot 1 » Implementing OAuth2 » 2022-07-19 12:35:17

squirrel wrote:

Does anybody still have copies of these gists available? I need a mormot server with oauth authentication and was hoping this would be something to build on.  But the gists seem to be all gone already.

email sent

#16 Re: mORMot 1 » A small example in response to a question » 2022-07-14 16:12:18

tbo wrote:

I have published my fourth article with the topic mORMot ...

Awesome!

#17 Re: mORMot 1 » A small example in response to a question » 2022-07-09 13:51:16

Hi Thomas!


   Thank you for your series of articles and samples! Have sure that they are helping clarify a little more the "how-to" in the mORMot world, that powerful but sometimes hermetic (until you figure it out...) series of frameworks.

   Have a great day!

#18 Re: mORMot 1 » Delphi compilation error with last commits » 2022-06-18 17:09:46

While Ab fixes that properly, you can do this to fix that compile error:

---
FormatString('%.%', [efn, ALGO_EXT[a]], String(fn));
---

#19 Re: mORMot 1 » New Async HTTP/WebSocket Server on mORMot 2 » 2022-05-21 17:53:58

Thank you, Ab, for the dedication and excellence of your framework! This article will help many who are just starting to understand this part of the powerful mORMot!

#20 Re: mORMot 1 » Deserializing JSON on mormot2 » 2022-05-17 18:38:20

ab wrote:

...
Edit:
I guess your code is wrong because you use String which is UnicodeString = UTF-16 on Delphi.
Replace tmp: RawUtf8; by tmp: RawUtf8; and I guess it would work.

That's it!! A 'RawUtf8' did the thing!!

I knew that the record as it is defined here is well dealt with by 'mORMot' because it worked before for other situations like that, but I didn't realize about 'RawUtf8'!

Thank you, Ab!

#21 Re: mORMot 1 » Deserializing JSON on mormot2 » 2022-05-17 17:03:04

Hello there,

Using the help provided here I could convert the JSON from a REST service from the format above shown on 'JSON_Test.TXT' to an array that is better handled by my application ('JSON_Test_03.txt'). However, although now it is an array I can't load it to an array using 'DynArrayLoadJson' as shown here: https://github.com/PrometeusRec/JSON_Te … N_Test.dpr

'new_array' is empty after calling 'DynArrayLoadJson'. I guess it was supposed to load that record correctly, but for some reason, it doesn't.

In the same application, I successfully loaded other JSON arrays similar to the one above, but sometimes 'DynArrayLoadJson' won't work as expected. Is there something wrong with the JSON file above for it not working?

#22 Re: mORMot 1 » Deserializing JSON on mormot2 » 2022-05-16 04:08:21

tbo wrote:

In your case you will find the object names as follows:

var
  doc: TDocVariantData;
begin
  if not doc.InitJsonFromFile('_testData.json', JSON_OPTIONS_FAST_EXTENDED) then Exit; //=>
  WriteLn(RawUtf8ArrayToCsv(doc.Names));

   Thanks, Thomas, ALL worked like a charm!

#23 Re: mORMot 1 » Deserializing JSON on mormot2 » 2022-05-15 17:14:35

igors233 wrote:

1) That is a valid JSON, it just doesn't write objects as array but as separate objects, Record01, Record02...
  You'll have to convert it to array manually, you can use TDocVariantData.InitJSON to read and fill whole content and then you'll have to go through it manually and convert it to your internal array of records.

Thanks for the tip, I'll check it out.

2) Yes, if you load that json in TDocVariantData you'll have json object with two properties, ABC and DEF (both are objects as well). So you could read it as
  with (there are other options), GetValueOrNull('ABC').

When you know the values it is ok, but what if you don't know previously that the values will be 'ABC', 'DEF'? Is there a parse function that will give you those values, so you can try the solution you told below for late binding?

#24 Re: mORMot 1 » Deserializing JSON on mormot2 » 2022-05-15 16:47:34

I am still learning the HUGE JSON framework of mORMot, but there are situations where I still don't know how to figure them out, like the one below:

1) I need to read JSON values that are like the one in the file 'JSON_Test.TXT' (link below). The values there are not properly an array (looking at the JSON file there is no '[',']' pair), but look like one, and neither is a sole record. Is there a mORMot function that can read it and fill an 'array of packed record' able to be read by a call like 'DynArrayLoadJson' for that situation?

2) Another question: Is there a way to read the values that precede the initial record ('Record01') of the set of records for each entity? For the specific file the values 'ABC' and 'DEF'?

https://github.com/PrometeusRec/JSON_Test

Thanks for any help!

#25 Re: mORMot 1 » Using mORMot to access ordinary WebSocket server » 2022-03-14 14:34:31

Prometeus wrote:

--> What is the proper method to send a text back to the server using the bidirectional open connection? Thanks!

   Nevermind, I made it using 'SendFrames'

#26 Re: mORMot 1 » Using mORMot to access ordinary WebSocket server » 2022-03-14 13:57:04

ab wrote:

IIRC a HTTP/1.1 upgrade should have no content-length by definition.

So that test had really passed!

What is the input headers content?

Perhaps the client has some unexpected headers.

Input headers were empty

Based on the test done by 'aProtocol.SetSubprotocol(prot)', I realized that the problem was when creating an instance of 'TWebSocketProtocolChat', where I was giving a name when calling 'Create'. It was not clear to me, based on the comments in the source code, what 'aName' meant exactly, and I thought it was a name the programmer was giving to that specific use. When I left it empty it passed the test done at line 451 (above) and worked as expected.

--> What is the proper method to send a text back to the server using the bidirectional open connection? Thanks!

#27 Re: mORMot 1 » Using mORMot to access ordinary WebSocket server » 2022-03-14 03:33:29

I verified that for the following line (451 - mormot.net.ws.client):

  if not IdemPChar(pointer(cmd), 'HTTP/1.1 101') or
         not (hfConnectionUpgrade in Http.HeaderFlags) or
         (Http.ContentLength > 0) or
         not IdemPropNameU(Http.Upgrade, 'websocket') or
         not aProtocol.SetSubprotocol(prot) then
        exit;

All five tests fail for "(Http.ContentLength > 0)", and only the last case passes for "not aProtocol.SetSubprotocol(prot)"

Still trying to figure out why it doesn't upgrade for the first four cases

#28 Re: mORMot 1 » Using mORMot to access ordinary WebSocket server » 2022-03-13 15:14:20

I am still doing some tests with mORMot WebSockets but for some reason, I am getting 'Invalid HTTP Upgrade Header' after upgrading to WebSocket. I tried with five different WebSocket servers that I found on Internet, but for only one of them, the result was ok, although they are all supposed to respond the same way, with JSON or plain text.

I did a simple test program here https://github.com/PrometeusRec/mormot_ … t_Test.dpr where you can see the five websites above, and uncomment one website at a time and test it. Currently, only the last one is giving an answer different from 'Invalid HTTP Upgrade Header' after calling 'WebSocketsUpgrade'. I tested all those websites on 'https://www.piesocket.com/websocket-tester#' and all worked as expected. For two of those, you can enter the JSON  in the comments if you want to see them respond, as all the others will give an automatic response right after the connection.

What is the proper method to send a text back to the server using the bi-direction open connection? Thanks!

#29 mORMot 1 » Compiling error in mormot.net.sock » 2022-03-11 21:28:31

Prometeus
Replies: 1

Compiling error at:

[dcc32 Error] mormot.net.sock.pas(1353): E2441 Inline function declared in interface section must not use local symbol 'PSockAddr'

Delphi 11

#30 Re: mORMot 1 » Using mORMot to access ordinary WebSocket server » 2022-03-10 21:16:08

Indeed, I was mixing those pieces of information. Thanks!

#31 Re: mORMot 1 » Using mORMot to access ordinary WebSocket server » 2022-03-10 16:23:03

Thanks for the suggestion about the best protocol in my case.

However, I can't test that point because I am stuck on try connecting to the server. I can't test the rest of my code because I can't go on from the connection phase. I tried different WebSockets servers and the result was always the same ('Is a server available on this address:port? THttpClientWebSockets.OpenBind({websocket site}) [Not Found - #3]'):

var ClientWS         : THttpClientWebSockets;
    WSSConnection : TGetWSSRequests;
    lProto               : TWebSocketProtocolChat;

begin 
  WSSConnection := TGetWSSRequests.Create;
  ClientWS := THttpClientWebSockets.Create;
  ClientWS.OnCallbackRequestProcess := WSSConnection.DealWSSRequests;
  ClientWS.Open('wss://socketsbay.com/wss/v2/2/demo','443'); //                        <--- HERE it raises the error I told in my first message
...

  I don't need a REST WebSocket in my case, and that's why I am using 'THttpClientWebSockets'. Unfortunately, while I tried looking through the mORMot 2 source code and samples, I didn't find the right way to work with 'THttpClientWebSockets' so far. I thought it was like 'TSimpleHttpClient' with the particularities of 'WebSockets', eg. the callback functions. All samples that I saw about this matter were using both server and client using mORMmot. I didn't see a sample for using WebSockets to talk to an ordinary WebSocket server.

#32 mORMot 1 » Using mORMot to access ordinary WebSocket server » 2022-03-10 01:30:22

Prometeus
Replies: 9

Hello,

I have seen some mORMot samples showing up how to create both server and client using WebSocket, using different protocols. I created a simple client to communicate with an ordinary WebSocket server, and when I try using a 'THttpClientWebSockets' to access it when I do a 'Client.Open(WSS site, port)' I receive a 'Is a server available on this address:port? THttpClientWebSockets.OpenBind({websocket site}) [Not Found - #3]' error message. The WebSocket site is working ok, and I've tested it using one WebSocket tester website, like 'https://www.piesocket.com/websocket-tester', receiving the expected initial message.

Can an ordinary WebSocket server be accessed through mORMot using 'THttpClientWebSockets'? I tested both '80' and '443' ports that I guess are the ones to access the WebSocket server that I need because the above WebSocket tester even needs a port in the URI for accessing the server. In case that is possible, the best protocol to be used would be 'TWebSocketProtocolJson'? The server uses plain JSON to receive commands and send responses.

Thanks for any help!

#33 mORMot 1 » Error in mormot.core.buffers » 2022-03-07 04:26:45

Prometeus
Replies: 2

When I tried recompiling a code using the latest mORMot 2 source code I got the following error:

[dcc32 Error] mormot.core.buffers.pas(2228): E2169 Field definition not allowed after methods or properties

Delphi 11

#34 Re: mORMot 1 » Deserializing JSON on mormot2 » 2022-01-19 23:30:29

ab wrote:

It is because your code is incorrect.

The JSON is an object holding an array, not an array itself.

  Ok, thanks!

#35 Re: mORMot 1 » Deserializing JSON on mormot2 » 2022-01-19 22:00:10

Hi Thomas and Arnaud!

   I can confirm that. I am using Delphi 10.3.3. 'DynArrayLoadJson' didn't work in this case. The fix shown by Thomas worked as expected, but why was it necessary to create a 'packed record' type of the array of the fields loaded from the JSON, and not the array type itself? I didn't see that need when I read the item '10.1.3.2.4 Text-based definition' of mORMot's documentation.

   Thank you!

#36 mORMot 1 » Deserializing JSON on mormot2 » 2022-01-19 19:26:53

Prometeus
Replies: 15

Hi there,


   While learning more about mORMot2 I am doing some tests with JSON. I am loading a JSON and trying to deserialize it with 'DynArrayLoadJson'. You can check it here https://github.com/PrometeusRec/mormot_ … n/Test.pas
   
   The JSON file test is there as well. However, no 'JSON' is being loaded into the array. My questions are:

1) Is the JSON content different from what  'DynArrayLoadJson' expects, or is there some error in the type of the fields?

2) On that sample 'packed record' created there is a commented field that is not present in the JSON that I need to read (the exact type shown in the '.TXT' file). The original 'JSON' file may have more fields than the 'packed record' that you will need, but the contrary is not allowed? I would like to make some processing and save the results in fields of the same 'packed record'. Is that possible?

   Thanks!

#37 Re: mORMot 1 » Error accessing an external Firebird database » 2020-12-07 17:00:27

ab wrote:

No, the default authentication has a specific signature computed for each URI.
Check the documentation about it.

What you can do is use a JWT instead.

Thank you for the prompt answer. I think you are talking about my second question when I try to access the REST API using authentication, but my current test (using SSL) is not using authentication (I did it without SSL and it worked according to documentation), so the signature computed for a URI should not be used in this case, right? What is the cause of the "Authentication Failed: Invalid signature (0)" message?

#38 Re: mORMot 1 » Error accessing an external Firebird database » 2020-12-07 16:49:37

igors233 wrote:

No, speed is same, I say it's easier to maintain. I've started too with SQLModel for existing FB that's used outside of my app and I've transitioned to interface based approach, following sqlmodel proved too restrictive especially since I need data from several tables.

The applications use the FB database, and now it will be accessed by a mobile application as well. I am really impressed with SQLite 3 performance, and I thought about converting the FB database to it, but I am concerned about SQLite issues with simultaneous writing. I don't know SQLite well, but I am aware of its limitation when dealing with concurrency writings, so I will stick with an external database for while.

I already followed Mormot documentation about SSL, and I am trying to test it using Chrome or Firefox. Despite Chrome not liking my "Dev Certification Authority" and showing it as "Not Secure" (For Firefox it is ok), I am doing simple tests using a browser, and after that build the client-side. After the SLL all set, I am trying accessing the REST API with SSL enabled (the source above was updated):

'https://localhost:8043/root/test/1'

and I am receiving:

{
"errorCode":403,
"errorText":"Authentication Failed: Invalid signature (0)"
}

Googling a little, I found that this message is related to a problem in authenticating. However, I am setting 'aHandleUserAuthentication' to 'false', at first. 'AUTHGROUP' and 'AUTHUSER' tables were created by Mormot when I was testing authenticating without SSL (I guess that they are only used if 'aHandleUserAuthentication' is set to 'true', right?), but I want to have the REST API accessing working with SSL without authentication first, then with it.

After fixing this issue (accessing the REST API through a browser or AJAX client) can the right above input using authentication like this?

'https://localhost:8043/root/test/1?user=User&password=synopse'

#40 Re: mORMot 1 » Error accessing an external Firebird database » 2020-12-04 02:39:28

igors233 wrote:

So you have some existing Firebird DB and you want to serve data from it though REST server?
Note that in such case I would skip altogether defining TSQLModel with existing tables and using FB as external DB. Write interface service that would connect to database (with zeos for example), get data as json and return it to client.

Thank you for the suggestion. I already got my application test working as expected and using the 'standard' way with TSQLModel. I have included in my tests Mormot secure authentication and it worked too, and now I am trying to have it working with SSL. Is there a real advantage for using interface services, like more speed in the JSON response, for instance? I still didn't study this part of Mormot documentation, but anyway I am already glad about the results that I am getting. Mormot framework is the most impressive piece of code for Delphi in this area that I have seen, and I wonder why I didn't hear about it before.

#41 Re: mORMot 1 » Error accessing an external Firebird database » 2020-11-20 17:11:23

The test table already exists. I created a fresh Firebird database with just one table and two fields only to begin to understand and learn the Mormot framework. I was expecting that the "CreateMissingTables" call create the 'ID' field on that table. However, that is not happening and, according to the error posted, "CreateMissingTables" is trying to read that field, when the error occurs.

#42 mORMot 1 » Error accessing an external Firebird database » 2020-11-20 04:11:19

Prometeus
Replies: 12

Hello,

I begin using the Mormot framework and my primary interest in it is as a REST server. I read some docs about how to do for Mormot to access external databases (Firebird in this case), including the Mormot manual related, and I created a small test, but it is raising an error when I call 'CreateMissingTables'. The code and the error message generated are at https://gist.github.com/PrometeusRec/c4 … 68732fbd9f

I am using the latest 'Zeos' version and compiling for Delphi 10.3.3

I am trying to fix this basic thing for two days, but I can't understand what is wrong with it. The 'TEST.FDB' database has just two raws but looks like the 'ID' field is not being really created in the 'CreateMissingTables' call, but it thinks that it was, and then the error message raised. Am I missing something for this test work?

Thanks for any help.

Board footer

Powered by FluxBB