4
votes

I used the Firedac connection recovery feature as described at Recovering Connection (FireDAC) and everything worked fine with Delphi XE5.

I installed Delphi community versions 10.2, 10.3 and 10.3.1 for migration testing and found that the database reconnect feature is not working as it should.

Scenario of use:

  • Windows 10 PRO X64 1803
  • Delphi 10.2 / 10.3 / 10.3.1
  • PostgreSQL 9.5.16 x64

Steps to reproduce the problem:

1 - Create a new VCL application;

2 - On Form1, drop the components TFDConnection, TFDPhysPgDriverLink, TFDGUIxWaitCursor, TFDQuery and TButton;

3 - Configure the TFDConnection with the connection parameters for PostgreSQL and vendorlib libpq.dll for TFDPhysPgDriverLink;

4 - Configure the TFDConnection as described at Recovering Connection (FireDAC);

5 - In the TButton OnClick event place the following:

qry1.Close;
qry1.Open ('select 1');

6 - In the OnRecover event of TFDConnection put the code below, as described at Recovering Connection (FireDAC):

var
  iRes: Integer;
begin
  iRes: = MessageDlg ('Connection is lost. Offline - yes, Retry - ok, Fail - Cancel', mtConfirmation, [mbYes, mbOK, mbCancel], 0);
  case iRes of
    mrYes: AAction: = faOfflineAbort;
    mrOk: AAction: = faRetry;
    mrCancel: AAction: = faFail;
  end;
// Log ('Connection is recovering');

7 - Run the application;

8 - Click the TButton once;

9 - Restart the PostgreSQL service or disable / re-enable the network adapter;

10 - Click on the TButton again and note that the TFDConnection component didn't trigger the OnRecover event, instead, the following error is displayed:

[FireDAC] [Phys] [PG] [libpq] server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request.

Clicking again on the TButton another error is displayed every time:

[FireDAC] [Phys] [PG] [libpq] no connection to the server

Thanks in advance for reviewing this.

This question has similarity to my case, but it was for Delphi 10: When PostgreSQL stops TFDConnection.Connected remains True

1
Did you try TFDCustomConnection.Ping first before qry1.Close, to see if this fails too?mjn
@mjn, thanks for comment. I tried but nothing change. The problem persists.Zeus-Adenilton
Did you accidentally add the EFDDBEngineException to the list of suppressed exceptions? (See 'Language Exceptions' in IDE options)mjn
@mjn, Thanks again, but EFDDBEngineException wasn't ignored in the Delphi's configuration. For example, in the step 9, if I disable network adapater, leave it disabled and then execute step 10, TFDConnection.OnRecover event is fired. The problem ocurrs when service restart or in unstable networks. But everything was working fine in Delphi XE5.Zeus-Adenilton
You'd better add this patch as an answer.Paul

1 Answers

1
votes

I reported this problem to Embarcadero quality central, according RSP-23958, and the bug are comproved of them. Someone called Dmitry answered that the problem will be fixed with update 2 of Delphi 10.3.

In the RSP-23958, was attached a fix patch that solve the problem and you you can use it, if you have Dephi with Firedac source code, while Delphi 10.3 update 2 not released.

The fix is bellow:

Index: runtime/data/firedac/FireDAC.Phys.PGWrapper.pas
===================================================================
--- runtime/data/firedac/FireDAC.Phys.PGWrapper.pas (revision 95224)
+++ runtime/data/firedac/FireDAC.Phys.PGWrapper.pas (revision 95225)
@@ -1109,7 +1109,9 @@
      FDStrLike(sLCMessage, 'password authentication failed for user "%"') then
     eKind := ekUserPwdInvalid
   else if (Pos('connection refused', sLCMessage) <> 0) or
-          (Pos('could not connect to server', sLCMessage) <> 0) then
+          (Pos('could not connect to server', sLCMessage) <> 0) or
+          (Pos('server closed the connection unexpectedly', sLCMessage) <> 0) or
+          (Pos('no connection to the server', sLCMessage) <> 0) then
     eKind := ekServerGone
   else
     eKind := ekOther;