Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-09

PostgreSql: unexpected EOF on client connection with an open transaction

11 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Leonardo M. Ramé

Hi, this is kind of a dejavu, I'm pretty sure I have asked this question before, but I can't find the old message, so, here I go.

In my postgresql.log file I get this two messages every time I query/update the database:

could not receive data from client: Connection reset by peer unexpected EOF on client connection with an open transaction

I'm using TPQConnection/TSqlTransaction/TSqlQuery in a CGI with this method:

procedure TDataModule1.ExecSql(ASql: string);
var
   lSql: TSQLQuery;
begin
   lSql := TSQLQuery.Create(nil);
   try
     lSql.DataBase := PQConnection1;
     lSql.Transaction := SQLTransaction1;
     lSql.SQL.Text:= ASql;
     lSql.ExecSQL;
     SQLTransaction1.Commit;
   finally
     lSql.Free;
   end;
end;

The query is executed without issues, data is stored into the db, but I keep getting those messages.

I'm using FPC 3.1.1 - Lazarus 1.5 - Linux 64bits (Ubuntu 15.04).

Regards,

Reply by email

Marc Santhoff
to Leonardo M. Ramé
Leonardo M. Ram? wrote 22 lines
Hi, this is kind of a dejavu, I'm pretty sure I have asked this question before, but I can't find the old message, so, here I go. In my postgresql.log file I get this two messages every time I query/update the database: could not receive data from client: Connection reset by peer unexpected EOF on client connection with an open transaction I'm using TPQConnection/TSqlTransaction/TSqlQuery in a CGI with this method: procedure TDataModule1.ExecSql(ASql: string); var lSql: TSQLQuery; begin lSql := TSQLQuery.Create(nil); try lSql.DataBase := PQConnection1; lSql.Transaction := SQLTransaction1; lSql.SQL.Text:= ASql; lSql.ExecSQL; SQLTransaction1.Commit;

Only guessing: maybe the transaction object is set to "autocommit" and the .Commit statement produces the error?

Marc

Show quoted text 11 lines
finally lSql.Free; end; end; The query is executed without issues, data is stored into the db, but I keep getting those messages. I'm using FPC 3.1.1 - Lazarus 1.5 - Linux 64bits (Ubuntu 15.04). Regards,
Marc Santhoff

Reply by email

Mark Morgan Lloyd
to Marc Santhoff
Marc Santhoff wrote 26 lines
On Di, 2015-09-01 at 14:26 -0300, Leonardo M. Ram? wrote: > Hi, this is kind of a dejavu, I'm pretty sure I have asked this question > before, but I can't find the old message, so, here I go. > > In my postgresql.log file I get this two messages every time I > query/update the database: > > could not receive data from client: Connection reset by peer > unexpected EOF on client connection with an open transaction > > I'm using TPQConnection/TSqlTransaction/TSqlQuery in a CGI with this method: > > procedure TDataModule1.ExecSql(ASql: string); > var > lSql: TSQLQuery; > begin > lSql := TSQLQuery.Create(nil); > try > lSql.DataBase := PQConnection1; > lSql.Transaction := SQLTransaction1; > lSql.SQL.Text:= ASql; > lSql.ExecSQL; > SQLTransaction1.Commit; Only guessing: maybe the transaction object is set to "autocommit" and the .Commit statement produces the error?

I saw a suggestion earlier via Google (which I probably can't find again) that after the query had been executed an implicit begin would be reissued.

Show quoted text 9 lines
> finally > lSql.Free; > end; > end; > > The query is executed without issues, data is stored into the db, but I > keep getting those messages. > > I'm using FPC 3.1.1 - Lazarus 1.5 - Linux 64bits (Ubuntu 15.04).
Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Michael Van Canneyt
to Leonardo M. Ramé: Hi, this is kind of a dejavu, I'm pretty sure I have asked this question before, but I…
Leonardo M. Ram? wrote 29 lines
Hi, this is kind of a dejavu, I'm pretty sure I have asked this question before, but I can't find the old message, so, here I go. In my postgresql.log file I get this two messages every time I query/update the database: could not receive data from client: Connection reset by peer unexpected EOF on client connection with an open transaction I'm using TPQConnection/TSqlTransaction/TSqlQuery in a CGI with this method: procedure TDataModule1.ExecSql(ASql: string); var lSql: TSQLQuery; begin lSql := TSQLQuery.Create(nil); try lSql.DataBase := PQConnection1; lSql.Transaction := SQLTransaction1; lSql.SQL.Text:= ASql; lSql.ExecSQL; SQLTransaction1.Commit; finally lSql.Free; end; end; The query is executed without issues, data is stored into the db, but I keep getting those messages.

Do you have a second transaction object (e.g. default transaction) ? If so, that's probably it.

Michael.

Reply by email

Leonardo M. Ramé
to Michael Van Canneyt
Show quoted text 6 lines
Do you have a second transaction object (e.g. default transaction) ? If so, that's probably it. Michael.

No, just a TSQLTransaction attached to the TPQConnection object.

I commented all my code but the PQConnection1.Connected := True, and I noted I get the "could not receive data from client: Connection reset by peer" message just after the CGI program ends its execution.

Reply by email

Michael Van Canneyt
to Leonardo M. Ramé
Leonardo M. Ram? wrote 12 lines
> Do you have a second transaction object (e.g. default transaction) ? > If so, that's probably it. > > Michael. > > No, just a TSQLTransaction attached to the TPQConnection object. I commented all my code but the PQConnection1.Connected := True, and I noted I get the "could not receive data from client: Connection reset by peer" message just after the CGI program ends its execution.

Are you closing the connection properly ? i.e. not through Free, but through close.

Michael.

Reply by email

Leonardo M. Ramé
to Michael Van Canneyt

El 02/09/15 a las 15:09, Michael Van Canneyt escribi?:

Show quoted text 11 lines
On Wed, 2 Sep 2015, Leonardo M. Ram? wrote: >> Do you have a second transaction object (e.g. default transaction) ? >> If so, that's probably it. >> >> Michael. >> >> >

Yes, I added an onDestroy event to the datamodule containing the PQConnection object and called PQConnection.Close(), but the efect is the same. BTW, the onCreate event is who calls PQConnection.Connect := True.

There must be a problem in the CGI, because I created a desktop app with just a PQConnection, SQLTransaction and SQLQuery and the message isn't logged on the server's log.

Reply by email

Michael Van Canneyt
to Leonardo M. Ramé
Leonardo M. Ram? wrote 20 lines
El 02/09/15 a las 15:09, Michael Van Canneyt escribi?: > > > On Wed, 2 Sep 2015, Leonardo M. Ram? wrote: > >>> Do you have a second transaction object (e.g. default transaction) ? >>> If so, that's probably it. >>> >>> Michael. >>> >>> >> Yes, I added an onDestroy event to the datamodule containing the PQConnection object and called PQConnection.Close(), but the efect is the same. BTW, the onCreate event is who calls PQConnection.Connect := True. There must be a problem in the CGI, because I created a desktop app with just a PQConnection, SQLTransaction and SQLQuery and the message isn't logged on the server's log.

Well, that is why I asked how it is closed.
Maybe it was closed a different way in your CGI, without properly closing it. The strange thing is that it reports an active transaction.

Do you open a dataset ? If so, try setting Unidirectional:=True before opening it.
(this avoids extra queries to fetch unique key data etc.)

Michael.

Reply by email

Leonardo M. Ramé
to Michael Van Canneyt

El 02/09/15 a las 16:00, Michael Van Canneyt escribi?:

Show quoted text 9 lines
Well, that is why I asked how it is closed. Maybe it was closed a different way in your CGI, without properly closing it. The strange thing is that it reports an active transaction. Do you open a dataset ? If so, try setting Unidirectional:=True before opening it. (this avoids extra queries to fetch unique key data etc.)

No, the error is raised even when I only have a TDataModule with a PQConnection.Connect on it's onCreate event.

I'll ask Silvio, because I'm using Brook Framework, and maybe the way TBrookApp is handling creation/drestruction of TDatamodule is different than with TApplication, and it seems that onDestroy is not called.

Reply by email

Leonardo M. Ramé
to Leonardo M. Ramé

El 02/09/15 a las 16:11, Leonardo M. Ram? escribi?:

Show quoted text 19 lines
El 02/09/15 a las 16:00, Michael Van Canneyt escribi?: > > Well, that is why I asked how it is closed. Maybe it was closed a > different way in your CGI, without properly closing it. > The strange thing is that it reports an active transaction. > > Do you open a dataset ? If so, try setting Unidirectional:=True before > opening it. > (this avoids extra queries to fetch unique key data etc.) > No, the error is raised even when I only have a TDataModule with a PQConnection.Connect on it's onCreate event. I'll ask Silvio, because I'm using Brook Framework, and maybe the way TBrookApp is handling creation/drestruction of TDatamodule is different than with TApplication, and it seems that onDestroy is not called.

I think I found a bug in Brook.

My .lpr now has this:

begin
   BrookApp.CreateForm(TDataModule1, DataModule1);
   BrookApp.Run;
   DataModule1.Free; // this fixes the issue.
end.

Reply by email