say I ask my database to kill all its open connect...
# lucee
d
say I ask my database to kill all its open connections, can I inform lucee about this and ask lucee to reopen a connection for some datasource?
b
@David Rogers Every 60 seconds or so, Lucee will test every connection it has to see if it's still valid. if not, it will be discarded.
Lucee creates new connections at the point you run a cfquery if there are no good ones left in the pool
The typical problem with killing them DB-side is the next CF request may attempt to use the connection object which errors, (and triggers it to be discarded) and then will work again on the next attempt. You can eliminate this by checking the
Validate
checkbox for the datasource
Copy code
Validate the connection before use (only works with JDBC 4.0 Drivers)
which is the Lucee equivalent to Adobe CF's "validation query" feature, except you don't have to specify a query.
d
i have something like
Copy code
queryexecute("
kill every connection to some_test_db;
-- do other stuff
", {}, {datasource: "master/i.e. not some_test_db"})
which works every other request (coinciding with the above comment it seems) (edited for marginally improved clarity)
👍 1
b
I'm not quite clear what you're doing, but if that SQL kills any open connections, then yeah it would be an issue.
Check the "validate" box and see if Lucee checks the cached connection first before trying it the next time
It's also worth noting here, Adobe CF allows you to completely disable pooled connections (forcing a new DB connection for every request), but Lucee does not.
d
naively I'd have figured that's a driver option, c'est la vis
b
here is the setting
message has been deleted
Not to be confused with the "verify" checkbox which only applies to the save operation right then
d
hm, what happens if the connection is dead and it doesn't validate it as dead...I guess I will find out!
d
I would just add that while the overhead may be minimal, if you choose to validate before each request it does add some overhead. If you're trying to force the connection for the same request, you could just manually fire off a validation query in a try/catch, which I think then on the second attempt should re-open the connection.
d
if you choose to validate before each request
as in, the box Brad posted is checked, yes?
b
hm, what happens if the connection is dead and it doesn't validate it as dead...I guess I will find out!
Huh? What do you mean? Are you saying the JDBC driver may have a bug and not work correctly?
d
i might not be correctly using the term/idea "connection"
b
if you choose to validate before each request it does add some overhead.
This is correct. I'm fairly sure the JDBC-level verification doesn't actual run any SQL, it just sends a round trip ping to the server to ensure it's still there.
you could just manually fire off a validation query in a try/catch,
While this work "work", it seems worse in every possible way 😆 It's for sure going ot be more overhead. I'd let the JDBC drivers do their thing. The validation process is actually built into the JDBC spec and lucee is simply asking the JDBC driver to check the connection to make sure it's life still.
connection
At a low level, an instance of a "connection" class in Java represents an open TCP channel. In this case, from Lucee to the DB server.
d
@bdw429s I just meant if he has a specific request in which he's killing the connections, but later wants to run some queries in the same request, he could manually validate. Not that you'd want to do that on every request. Obviously, that doesn't solve issues with other running requests.
b
Ahh, I see what you mean-- the problem is even if only one request kills the connection, the "dead" connection object would still cause an error on whatever random request tried to use it next
So as soon as you introduce the possibility of the connection being killed without java knowing it, every connection must verify in order to be safe
This is actually what Lucee calls, which I guess technically isn't part of the JDBC spec. It's just oart of the
java.sql.Connection
class https://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html#isValid(int)
d
oh, i'm not validating before use but should be in this case ... I thought it was the other way around ... hm, actually not sure, gotta look at my settings. this is a good intro I appreciate it gents
b
i'm not validating before use
To be clear, it's not an action you need to take in your code. You just check the box in the admin and you're done. Lucee does it for you when checking a connection out of the pool before it it used to execute your query. If it isn't valid, lucee discards it and takes another from the pool. Rinse and repeat until a valid connection is found, or a new one is created.
s
is this something that can be added to the Application.cfc datasource definition or is it only an admin/cfconfig setting?
b
@sknowlton It can be done in application.cfc
If you edit a datasource and scroll to the bottom in the admin UI you can see ti in the this.datasource example
Copy code
this.datasources["foo"] = {
     ...
	, validate:true // default: false
};