access violation in simultaneous request of the same resource using service.

we are using firebird 3 and the response time for this request is around 5 seconds. attached is an example simulating the situation. have a dataModule with a connection to firebird and another to sqlLite to change the connection to the database just go to the uDmServer unit and change it to XDataConnectionPool1. run the TesteServiceSimultaneous project in debug mode, click on the Fill base button, after the message finish, run the XDataClientServiceSimultaneous project application, click on the 2 calls button, after the second Manager/Qtde appears: in the memo close the TesteServiceSimultaneous application and wait for delphi that the access violation will occur. (614.7 KB)

was it possible to simulate the error or do you need some more information?

You are returning way too many objects, and XData is taking time to destroy them. One solution is to avoid asking XData to destroy them, adding this line to your server method:

  TXDataOperationContext.Current.Handler.ActionResultDestruction := TActionResultDestruction.RootOnly;

This should solve the issue. But it's always recommended to not return that many objects from the server in one single request.

in real application the access violation error is not because of a large amount of registration in the return, but because a query takes 4 seconds but with other queries simultaneously. this happens using firedac if using dbexpress error does not happen. I can't simulate this situation in a separate application. can i pass the full source or remote connection. follows a log with two connection types. (2.5 KB)

If it's a different situation we need again a project to consistently reproduce the issue.
Regardless if the error is similar (Access Violation at the end of application, due to requests taking too long), I can say that it's not a big issue per se, because this error only happens indeed when the server is closed, not while it's running.

You can try to manually increase the server stop timeout to a higher value so that all requests are fully processed before the server stops. You have to modify Sparkle source code for that, in unit Sparkle.Sys.ThreadPool, modify the DefaultStopTimeout value and recompile the packages:

  TThreadPool = class
    const DefaultStopTimeout = 20000;

in an attempt to simulate the error with a separate application we identified that the problem was in our code when passing the connection to xdata. we were doing like this:
FConnFactory := TDBConnectionFactory.Create(
function: IDBConnection
Result := TConexao.GetInstance.Local;

FConnPool := TDBConnectionPool.Create(2, FConnFactory);
FXDataModule := TXDataServerModule.Create(BaseUrl, FConnPool);
it worked just like this:
FXDataModule := TXDataServerModule.Create(BaseUrl, TConexao.GetInstance.Local);

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.