Unpool Connections and Error Number Lookup #57
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Due to VPN issues in our production environment I have a quality of service requirement to inspect the FreeTDS error numbers which might have occurred on a Connection and if certain errors have occurred, then ensure that the connection is not re-used (not returned to the connection pool).
To support error number lookup efficiently I have added function HasErrorNumber, which provides a goroutine safe (mutex controlled) map of FreeTDS error numbers and their assigned string. This is very similar to the Conn.HasMessageNumber functionality I have added previously.
To support not releasing connections back into the pool, two new functions have been added:
Conn.RemoveFromPool() will remove the connection from the pool and return it.
This allows the user to write calls such as: c1.RemoveFromPool().Close()
It also means that the function making the call doesn't need access to the actual pool object as well.
ConnPool.Remove() will remove the supplied Conn from the Pool.
Both functions are safe to call repeatably and if the conn is not actually in the pool.
Additional unit tests have been added to cover the new functionality.
They can be run with --race to prove goroutine safety:
go test --race
All existing unit tests pass.