You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by Christian Adams <ch...@comlet.de> on 2005/09/28 09:19:27 UTC

Changes of ODBCAppender's close() method

Hi

I had to do these changes to the methode close() from the ODBCAppender:
Would you like to include them in your code?

virtual void close()
{
	if (this->closed)			<<<<<<<<<<<<<<<<<<
	{					<<<<<<<<<<<<<<<<<<
		return;				<<<<<<<<<<<<<<<<<<
	}					<<<<<<<<<<<<<<<<<<
	
	try
	{
		flushBuffer();
	}
	catch (SQLException& e)
	{
		errorHandler->error(_T("Error closing connection"),
			e, log4cxx::spi::ErrorCode::GENERIC_FAILURE);
	}

	if (connection != SQL_NULL_HDBC)
	{
		SQLDisconnect(connection);
		SQLFreeHandle(SQL_HANDLE_DBC, connection);
		connection = SQL_NULL_HDBC;	<<<<<<<<<<<<<<<<<<
	}
	
	if (env != SQL_NULL_HENV)
	{
		SQLFreeHandle(SQL_HANDLE_ENV, env);
		env = SQL_NULL_HENV;		<<<<<<<<<<<<<<<<<<
	}
	
	this->closed = true;
}

My reasons:
My application crashes if I log into an postgres 8.0 DB while the
destructor destroys the Appenders.
(exactly at SQLFreeHandle(SQL_HANDLE_DBC, connection); in close() called 
from finalize() called from ~ODBCAppender().)
To avoid this crash (which only happens with postgres, not with mysql),
I have to close the appenders before their destructor is called. I do
this by removing all appenders from all loggers when my last
logger-wrapper will be destroyed. And there it can happen that close()
of one appender will be called twice (if two different loggers have the
same appender).
And than it is important to block this second call.

If all that is not postgres' error but mine or i can solve this problem
otherwise or someone has the same problem please answer!!

Thanks for reading

Christian Adams



Re: Changes of ODBCAppender's close() method

Posted by Andreas Fester <An...@gmx.de>.
Hi,

I have added your patch to my daily build. Should be available
in the daily dist-tarball at http://www.littletux.net/log4cxx tomorrow.

Thanks & best Regards,

	Andreas

Christian Adams wrote:
> Hi
> 
> I had to do these changes to the methode close() from the ODBCAppender:
> Would you like to include them in your code?
> 
> virtual void close()
> {
>     if (this->closed)            <<<<<<<<<<<<<<<<<<
>     {                    <<<<<<<<<<<<<<<<<<
>         return;                <<<<<<<<<<<<<<<<<<
>     }                    <<<<<<<<<<<<<<<<<<

-- 
Andreas Fester
mailto:andreas@littletux.net
WWW: http://www.littletux.net
ICQ: 326674288