#1 2021-07-05 11:06:12

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 223
Website

mORMot2 - Request terminated

Hi,

is there a way, possibly through ServiceRunningContext, to determine, whether the client has terminated the current request?

Offline

#2 2021-07-05 14:33:50

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

Re: mORMot2 - Request terminated

If the request is terminated, then ServiceRunningContext^.Request = nil.

But since the same thread could almost instantly been used by another request, ServiceRunningContext could also be reused.
So I don't think it is usable outside the thread of this request.

Offline

#3 2021-07-05 16:13:22

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 223
Website

Re: mORMot2 - Request terminated

I guess it would be a good idea, if there is a way to signal it to the running context in some way, for longer MVC ops to check on that. I tried studying the source for it, but could not make out a place where I could inject logic on that :-|

Regards,
Daniel

Offline

#4 2021-07-05 17:40:52

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

Re: mORMot2 - Request terminated

MVC is TRestServer-based so you have OnStartUri/OnBeforeUri/OnAfterUri events.

Which kind of callback do you need?
I have just introduced some dedicated TMvcApplication.OnBeforeRender/OnAfterRender callbacks.

Offline

#5 2021-07-05 19:55:26

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 223
Website

Re: mORMot2 - Request terminated

I wouldn't think about callback, rather just a field/property like ClientListening (definitely not the best name), that would be false, once disconnected. This way the methods could stop gathering/sorting/whatever data and abort upon checking that flag.
I guess that could be achieved just before setting ServiceRunningContext^.Request := nil.

Where does that "ServiceRunningContext^.Request := nil" happen? I'd be happy to check out a way for achieving that.

Regards,
Daniel

Offline

#6 2021-07-06 08:29:18

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

Re: mORMot2 - Request terminated

I don't understand what you expect.
There is nothing like a "connection", just requests. This is what the TRestServer and the new TMvcApplication.On*Render callbacks offer.

You may want to track sessions, so track cookies lifetime.
I have just added TMvcApplication.OnSessionCreate/OnSessionFinalized callbacks for this.

But I guess that most of this logic could be done in your MVC business code directly.

Offline

#7 2021-07-06 08:54:39

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 223
Website

Re: mORMot2 - Request terminated

Basically I am trying to find a way to check, whether the client has aborted the request in the meantime. In .NET running on http.sys you get something called a CancellationToken. That would allow canceling longer operations, when the client "lost interest".

Offline

#8 2021-07-06 11:57:10

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

Re: mORMot2 - Request terminated

Do you mean that the request could take a while, and that the socket has been closed on the client side before the answer is sent back?
For MVC views, which are made by the browser directly, there is no simple way of making the client close the connection.
For AJAX requests, you can call abort() before you get the answer, but I guess it is out of scope.

Our Web server is not meant for long requests. It consumes a thread of the thread pool during each request, so it would be easy to render the server unstable (typically make a DoS attack).
The MVC requests are meant to take a few milliseconds, tops.

So there is no "CancellationToken-like" feature in the mORMot server.
If you want to run some long-term process on the server side, you would rather use WebSockets or let the client poll the server for the task to be finished.
This is clearly out of scope of our MVC pattern.

Offline

#9 2021-07-06 12:55:01

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 223
Website

Re: mORMot2 - Request terminated

Not what I'd love to read, but I can live with that ;-)

Thanks

Offline

Board footer

Powered by FluxBB