Connection close filter

This is a special connection filter that gets called (if present and active) when a connection gets closed.

The main purpose of this filter type is to clean up anything you may have created during the lifetime of the connection, such as connections to resources.


Example

A typical use of this filter would be to close a database connection established by (for instance) a regular connection filter.

If we assume that you have a JavaScript connection filter with the following code:

if ( ! context.connectionContext.qres || !context.connectionContext.qres.conn.isValid(100)) {

log.debug("Opening connection to database");

let qres = context.utils.createObject();

let SQLServerDriver = Java.type("com.microsoft.sqlserver.jdbc.SQLServerDriver");

let driver = new SQLServerDriver();

qres.conn = driver.connect("jdbc:sqlserver://192.168.123.4;databaseName=MyDB;user=test1;password=xxxxx", null);

context.connectionContext.qres = qres;

}

then you could clean up that connection by creating a connection close filter with the following code:

context.connectionContext.qres.conn.close();