#1 2021-08-11 08:32:20

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 330

ERR_CONTENT_LENGTH_MISMATCH using mORMot2

Hi ab,

under Win64 (XE6) I got this error in all Browsers (Safari, Chrome, Firefox) at xhr response for big contents.
With mORMot(1.18) there is no such error.
Are there options I've to set for mORMot2?

Do you further informations?

Daniel

Offline

#2 2021-08-11 11:00:28

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

Re: ERR_CONTENT_LENGTH_MISMATCH using mORMot2

Using the very same server configuration?

Sometimes it comes from a nginx proxy problem.

Offline

#3 2021-08-11 11:33:19

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 330

Re: ERR_CONTENT_LENGTH_MISMATCH using mORMot2

Same configuration, absolute no changes.
We are using mORMot2 for production since 2-3 weeks and all works well. This error comes some days ago. I don't thought about mORMot2 but WLAN/network issues.
But this comes definitely from/with mORMot2 but just for larger responses, small one works fine.

Thanks for your great work again!

PS: for jit I personally would prefer BESEN. What I've seen and heart from bero simply destroys my self-confidence

Last edited by danielkuettner (2021-08-11 16:55:44)

Offline

#4 2021-08-11 11:52:15

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

Re: ERR_CONTENT_LENGTH_MISMATCH using mORMot2

How is the big content sent back to the client?
As regular in-memory buffers? As files?
Have you an estimate of the content size threshold which triggers the error?
Are you using the socket mORMot server on Linux/Windows, or the http.Sys mORMot server on Windows?

Is there a reverse proxy in-between mORMOt and the client?
Does it have a cache configured?
http://lfender6445.github.io/applicatio … -mismatch/

Offline

#5 2021-08-11 11:59:51

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 330

Re: ERR_CONTENT_LENGTH_MISMATCH using mORMot2

result := inherited Request(Ctxt);

in HttpServer.Request from a service call with standard RawJSON result (result:[JSON-Content from Service])

Offline

#6 2021-08-11 12:02:53

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

Re: ERR_CONTENT_LENGTH_MISMATCH using mORMot2

Do you use a reverse proxy?

Have you an estimate of the content size threshold which triggers the error?

Are you using the socket mORMot server on Linux/Windows, or the http.Sys mORMot server on Windows?

Is there any exception/error in the mORMot server log?

Offline

#7 2021-08-11 12:50:37

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 330

Re: ERR_CONTENT_LENGTH_MISMATCH using mORMot2

1. Yes I'm using a reverse proxy (apache2) from the beginning of my career.

2.
Length of Res (Service-Result) = 123579733
Length of Ctxt.OutContent = 123579746 (this is +13 of 123579733 (because of +'{"result":[]}' what's correct))

3.
No, no sockets

4. No exceptions, only in Client(Browser) with ERR_CONTENT_LENGTH_MISMATCH

PS: a Length of 28403957 works, but this is just an example, not a gap

Last edited by danielkuettner (2021-08-11 16:57:08)

Offline

#8 2021-08-11 13:06:09

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

Re: ERR_CONTENT_LENGTH_MISMATCH using mORMot2

120MB of content is indeed huge.

I am not able to see how Ctxt.OutContent may be smaller than expected.
Is Call.OutBody length correct?

Please try the following in TBaseWriter.AddNoJsonEscape:

...
      FlushToStream;
    until false;

i.e. delete all "if Len < f .... break;" part of the code.

Offline

#9 2021-08-11 13:29:00

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

Re: ERR_CONTENT_LENGTH_MISMATCH using mORMot2

I have just refactored TBaseWriter.AddNoJsonEscape for more efficient process.

The new algorithm may also help solve your issue. But I am not confident at all.

Offline

#10 2021-08-11 13:45:04

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 330

Re: ERR_CONTENT_LENGTH_MISMATCH using mORMot2

error still occurs after last update (14d8508bf1578e996542c44887e63efe91115972).

Ctxt.OutContent is not smaller, it's bigger, but seems to be wrong (when I can trust the Browsers).

I will follow your advices and give feedback...

Offline

#11 2021-08-11 14:57:33

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 330

Re: ERR_CONTENT_LENGTH_MISMATCH using mORMot2

at Service level Result is ok, in Http.Request Ctxt.OutContent is wrong often (not always).
Although length of Ctxt.OutContent is correct, you can't convert Ctxt.OutContent to _JSON (json is invalid here).

With mORMot1 length is the same as under mORMot2, but you can convert Ctxt.OutContent to _JSON without error.

In TBaseWriter.AddNoJsonEscape P can't parsed to json with _Json (TDocVariantData(Value).InitJson(Json, Options) gives false), but P parsed with JSON-Lint says "valid json"

I've to compare the P (mORMot1<>2) tomorrow.

Last edited by danielkuettner (2021-08-11 16:58:02)

Offline

#12 2021-08-11 19:24:13

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

Re: ERR_CONTENT_LENGTH_MISMATCH using mORMot2

What I usually do is to save huge context to files, then use a comparison tool like WinMerge or TotalCommander for comparison.

Maybe there is a buffer limit problem in some border case of TTextWriter... with file comparison it may become obvious.

Offline

#13 2021-08-12 04:51:34

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 330

Re: ERR_CONTENT_LENGTH_MISMATCH using mORMot2

I've looked for tools for that too and under linux there are also xxd and vimdiff or colordiff.

Last edited by danielkuettner (2021-08-12 04:56:01)

Offline

#14 2021-08-12 06:34:17

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 330

Re: ERR_CONTENT_LENGTH_MISMATCH using mORMot2

Ctxt.OutContent is perfectly identical (mORMot1 vs. mORMot2)! Not what I expected.

Seems to be a wrong content-length in http header. How can I check this value? In Ctxt I haven't found it?

As a side note, content won't parsed under mORMot2 by

_Json(JSON, Result, [dvoReturnNullForUnknownProperty, dvoAllowDoubleValue, dvoValueCopiedByReference]);
--> var JSON: RawUTF8, Result: Variant)

whereas under mORMot1 it will.

Offline

#15 2021-08-12 06:47:35

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

Re: ERR_CONTENT_LENGTH_MISMATCH using mORMot2

I have tried to reproduce the problem, having a new method returning 100MB of RawJson during the regression tests.
There was indeed a problem, and I just fixed TBaseWriter.AddNoJsonEscape to allow the CancelLastComma pattern to work as expected.
But I am not sure it was what happened for you.

Could you zip the content which fails to be parsed and put a link here (or send by email), so that I could try to reproduce it?

Offline

#16 2021-08-12 09:15:53

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

Re: ERR_CONTENT_LENGTH_MISMATCH using mORMot2

Update: I committed a series of fixes, including re-enabling HTTP server gzip compression which helps the clients in case of huge content.

Offline

Board footer

Powered by FluxBB