Subject | Re: [Firebird-Java] Connection does not close properly |
---|---|
Author | Lars George |
Post date | 2002-10-30T03:55:45Z |
Hi,
I kept debugging and found the problem. The socket is never explicitely
closed when the connection is 'destroyed'. Therefore the socket is closed at
the time the object is garbage collected. I added one line into the
GDS_Impl.isc_detach_database() method that calls a method that already
existed in that class. It closes the socket appropriately. Maybe this is an
oversight or intentionally, I do not know, but it works for me. Please
verify my fix and check it into the source repository if you think it is
making sense.
public void isc_detach_database(isc_db_handle db_handle) throws
GDSException {
isc_db_handle_impl db = (isc_db_handle_impl) db_handle;
if (db == null) {
throw new GDSException(isc_bad_db_handle);
}
synchronized (db) {
if (db_handle.hasTransactions())
{
throw new GDSException(isc_open_trans);
} // end of if ()
try {
if (log != null) log.debug("op_detach ");
db.out.writeInt(op_detach);
db.out.writeInt(db.getRdb_id());
db.out.flush();
if (log != null) log.debug("sent");
receiveResponse(db);
// lars 2002-10-30: Explicitely close socket to server
disconnect(db);
} catch (IOException ex) {
throw new GDSException(isc_network_error);
}
//db.rdb_transactions = new Vector();
}
}
Kind regards,
Lars
I kept debugging and found the problem. The socket is never explicitely
closed when the connection is 'destroyed'. Therefore the socket is closed at
the time the object is garbage collected. I added one line into the
GDS_Impl.isc_detach_database() method that calls a method that already
existed in that class. It closes the socket appropriately. Maybe this is an
oversight or intentionally, I do not know, but it works for me. Please
verify my fix and check it into the source repository if you think it is
making sense.
public void isc_detach_database(isc_db_handle db_handle) throws
GDSException {
isc_db_handle_impl db = (isc_db_handle_impl) db_handle;
if (db == null) {
throw new GDSException(isc_bad_db_handle);
}
synchronized (db) {
if (db_handle.hasTransactions())
{
throw new GDSException(isc_open_trans);
} // end of if ()
try {
if (log != null) log.debug("op_detach ");
db.out.writeInt(op_detach);
db.out.writeInt(db.getRdb_id());
db.out.flush();
if (log != null) log.debug("sent");
receiveResponse(db);
// lars 2002-10-30: Explicitely close socket to server
disconnect(db);
} catch (IOException ex) {
throw new GDSException(isc_network_error);
}
//db.rdb_transactions = new Vector();
}
}
Kind regards,
Lars