[Mono-devel-list] Npgsql possible bug

yoros at wanadoo.es yoros at wanadoo.es
Fri Dec 26 06:27:28 EST 2003


On Thu, Dec 25, 2003 at 11:37:06PM +0100, Jaroslaw Kowalski wrote:
> Hi all!
> 
> This is my first post to nant-devel-list, so please excuse any "formal"
> mistakes. I'm in progress of porting my O/R mapping solution to
> Mono/PostgreSQL and I've encountered the bug in Npgsql. Is this the right
> list to report this problem to?
> 
> The problem is related to the fact that NpgsqlCommand calls
> connection.Dispose() in it's Dispose method. This causes problems with
> constructs like the following, which are legal in MS.NET with MSSQL:
> 
> ---------------------------8<--CUT HERE------------------------------
> NpgsqlConnection conn = new NpgsqlConnection();
> 
> using (NpgsqlCommand cmd1 = new NpgsqlCommand("select * from ...", conn))
> {
>     cmd1.Execute...();
> }
> //
> // after exiting from the "using" block the Dispose on "conn"
> // is called causing it to close. The following command will
> // fail because the connection is no longer open.
> //
> using (NpgsqlCommand cmd2 = new NpgsqlCommand("select * from ...", conn))
> {
>     cmd2.Execute...();
> }
> ---------------------------8<--CUT HERE------------------------------
> 
> Proposed patch (made against today's AnonCVS) is to comment out the
> "connection.Dispose()" call. I believe this to be the correct semantics.
> 
> ---------------------------8<--CUT HERE------------------------------
> cvs server: Diffing .
> Index: NpgsqlCommand.cs
> ===================================================================
> RCS file: /mono/mcs/class/Npgsql/Npgsql/NpgsqlCommand.cs,v
> retrieving revision 1.11
> diff -u -r1.11 NpgsqlCommand.cs
> --- NpgsqlCommand.cs    12 Dec 2003 21:00:04 -0000      1.11
> +++ NpgsqlCommand.cs    25 Dec 2003 23:34:26 -0000
> @@ -619,10 +619,6 @@
>              NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME,
> "Dispose");
>              if (disposing)
>              {
> -                if (connection != null)
> -                {
> -                    connection.Dispose();
> -                }
>                  base.Dispose(disposing);
> 
>              }
> 
> ---------------------------8<--CUT HERE------------------------------
> 
> Can anyone review the patch and possibly commit it to CVS. I found it to be
> working quite well with my existing codebase.
> 

Yes, that code shouldn't be there but when we use NpgsqlDataAdapter with
DataSet, DataTable, etc... the connection is not closed:

	LOG:  pq_recvbuf: unexpected EOF on client connection

I think that when a command is disposed, it's underlying connection
shouldn't be disposed too but the physical connection can be closed and
the connection changes its inner state. In this way the connection can
be reopenend...

Please take care of what I said and, if you have time...

See you,

    Pedro

-- 
Pedro Martínez Juliá
\  yoros at terra.es
)|    yoros at wanadoo.es
/        http://yoros.dyndns.org
Socio HispaLinux #311
Usuario Linux #275438 - http://counter.li.org
GnuPG public information:  pub  1024D/74F1D3AC
Key fingerprint = 8431 7B47 D2B4 5A46 5F8E  534F 588B E285 74F1 D3AC



More information about the Mono-devel-list mailing list