#1 2025-12-03 18:02:28

gabrielbhz
Member
Registered: 2024-04-21
Posts: 2

How to disable service timeout only during long database processing?

Hello everyone,

I’m working with Delphi, mORMot 2 and FireDAC, and I have an issue related to service timeouts.

In my system, all business logic is implemented in the database. I use mORMot only as an HTTP layer to access and process data.
In some cases, executing a stored procedure may take a long time. When this happens, I face timeout problems on the mORMot server side, and the service instance is released even though the database processing has not finished.

To work around this, I temporarily disable the global service timeout using:

(RestServer.Services.Index(0) as TServiceFactoryServer).TimeoutSec := 0;

However, this affects all connections using the same service, which is not desirable.

My question:
Is there a way to disable or adjust the timeout only during the execution of a long-running process, without impacting other connections or service calls?

Any guidance or best practices would be greatly appreciated.

Thank you!

Offline

#2 2025-12-03 19:28:36

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,347
Website

Re: How to disable service timeout only during long database processing?

Don't try to tweak the timeout. It won't work because of the HTTP link itself, and that it would use one thread of the HTTP server thread pool.

Use a dedicated thread for the long process.

Switch to websockets and use the "long work callback" pattern.
See sample https://github.com/synopse/mORMot2/blob … server.dpr

Or switch to a "polling/asking" pattern if you can't use websockets.
With endpoints like "MyRequestStart()" and "MyRequestResult()"  methods, calling MyRequestStart() once but retrying MyRequestResult() every 100-500ms for instance, until it succeeded.

Offline

#3 2025-12-16 19:31:14

gabrielbhz
Member
Registered: 2024-04-21
Posts: 2

Re: How to disable service timeout only during long database processing?

Hello Ab, sorry for the delay in replying — I was only able to get back to the forum today.

WebSockets are indeed very interesting, but the learning curve and the effort required to implement them in my application would be quite high at the moment. I will try to follow the “polling/asking” approach instead, as I believe it can fit my use case well.

Thank you very much for the guidance!

Offline

#4 2025-12-17 14:17:58

zen010101
Member
Registered: 2024-06-15
Posts: 159

Re: How to disable service timeout only during long database processing?

I created a demo demonstrating the polling pattern solution for this issue: https://github.com/zen010101/Claude_Mor … -task-demo

Instead of a single blocking call, the client starts the task and polls GetTaskResult() periodically - each poll updates LastAccessTix10, keeping the session alive without disabling TimeoutSec globally.

Offline

#5 2025-12-17 14:24:51

zen010101
Member
Registered: 2024-06-15
Posts: 159

Re: How to disable service timeout only during long database processing?

===========================================
  Async Task Demo Client
  Demonstrates polling pattern
===========================================

Connected to server

Enter task duration in seconds (1-60): 10

Starting task with 10 second duration...
(Server timeout is 60s, but polling keeps session alive)

Task started with ID: 1

Status: Running... Progress: 4%
Status: Running... Progress: 9%
Status: Running... Progress: 14%
Status: Running... Progress: 20%
Status: Running... Progress: 25%
Status: Running... Progress: 29%
Status: Running... Progress: 35%
Status: Running... Progress: 40%
Status: Running... Progress: 45%
Status: Running... Progress: 50%
Status: Running... Progress: 55%
Status: Running... Progress: 60%
Status: Running... Progress: 65%
Status: Running... Progress: 71%
Status: Running... Progress: 75%
Status: Running... Progress: 80%
Status: Running... Progress: 86%
Status: Running... Progress: 90%
Status: Running... Progress: 95%
Status: COMPLETED!
Result: {"taskId":1,"taskName":"DemoTask","duration":10,"completedAt":"2025-12-17T19:51:42"}

Task finished!

Active tasks on server: 0

Press Enter to exit...

Offline

Board footer

Powered by FluxBB