Subject Re: NPE in isc_start_transaction (db.out.writeInt(op_transaction))
Author josef_gschwendtner
Hi Roman,

because we couldn't find a real solution for our problem we
implemented a (temporary) workaround.

Therefore we like to change Jaybird 1.5.5

With changing number 1 (see below) we shouldn't get the NPE anymore.
Because of throwing the GDSException the DB-Handle is going to be
destroyed. One record is lost but subsequent records are written
again (witout the change, the erroneous situation lasts for hours).

If we try to prevent to loose also this single record, a new handle
has to be created upon db.out == null.
Therefore we think about two other changings (see changing 2 and 3
below).

In our simulation these changings lead to a correct result, but we
don't know wether there are any side-effects or drawbacks. Nor do we
know, wether even more changes have to be done at other places.

Could you look over our changings and tell us your opinion or even a
better solution:-)

Hint:
We have done the following changings to find out wether it is
possible to get a new handle if db.out == 0.
We don't think this is a real solution.
On the other hand we like to know your opinion wether this could be a
temporarily solution.


Thank you very much for your help,
Josef


Changing No 1:
==============


Class GSD_Impl - Methode isc_start_transaction



isc_tr_handle_impl tr = (isc_tr_handle_impl) tr_handle;

isc_db_handle_impl db = (isc_db_handle_impl) db_handle;



if (tr_handle == null) {

throw new GDSException(ISCConstants.isc_bad_trans_handle);

}



if (db_handle == null) {

throw new GDSException(ISCConstants.isc_bad_db_handle);

}



// -----------------------------------------------------------
---------

// Begin: QS - 09.12.04

// Check if db.out == null

if (db.out == null){

if (log != null) log.error("Invalid db_handle (out ==
null)");

throw new GDSException(ISCConstants.isc_bad_db_handle);

}

// End: QS

// -----------------------------------------------------------
---------




Changing No. 2:
==============


Class FBManagedConnectionFactory – Methode getDbHandle



isc_db_handle getDbHandle(FBConnectionRequestInfo cri) throws
GDSException

{

try

{

LinkedList freeDbHandles = null;

synchronized (criToFreeDbHandlesMap)

{

freeDbHandles = (LinkedList)criToFreeDbHandlesMap.get
(cri);

}

if (freeDbHandles != null)

{

isc_db_handle db = null;

synchronized (freeDbHandles)

{

db = (isc_db_handle)freeDbHandles.removeLast();



// -----------------------------------------------
---------------------

// Begin: QS - 09.12.04

if (db != null) {

isc_db_handle_impl db_impl =
(isc_db_handle_impl) db;

if (db_impl.out == null){

if (log != null) log.warn("db_handle
invalid (out == null");

releaseDbHandle(db, cri);

return createDbHandle(cri);

}

}

// End: QS

// -----------------------------------------------
---------------------

}

return db;

} // end of if ()

return createDbHandle(cri);

}

catch (NoSuchElementException e)

{

return createDbHandle(cri);

}

}




Changing No. 3:
==============


Class FBManagedConnection – Methode getIscDBHandle



isc_db_handle getIscDBHandle(Set reserved) throws GDSException {

if (currentDbHandle == null) {

currentDbHandle = mcf.getDbHandle(cri);

}

else if (reserved.contains(currentDbHandle))

{

mcf.releaseDbHandle(currentDbHandle, cri);

currentDbHandle = mcf.getDbHandle(cri);

} // end of if ()





// -----------------------------------------------------------
---------

// Begin: QS - 09.12.04

isc_db_handle_impl db = (isc_db_handle_impl) currentDbHandle;

if (db.out == null) {

if (log != null) log.warn("db_handle invalid (out ==
null)");

mcf.releaseDbHandle(currentDbHandle, cri);

currentDbHandle = mcf.getDbHandle(cri);

// can we direct call mcf.createDbHandle() ?

}

// End: QS

// -----------------------------------------------------------
---------

return currentDbHandle;

}

--- In Firebird-Java@yahoogroups.com, "Roman Rokytskyy"
<rrokytskyy@a...> wrote:
> > Now the questions:
> > ==================
> > Can you think of a situation where a isc_db_handle instance is
> > invalid (db.out == null)?
> > Could it be a synchronization problem in JBoss or Jaybird?
>
> It, most likely, happens when server reports an error that is
considered to
> be "fatal" from the point of view of the driver. This invalidates
current
> connection and opens a new one. However, it seems that the
transaction
> handle is not marked as invalid and is later used by some
connection. At
> that point NPE happens.
>
> Roman