Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unpool Connections and Error Number Lookup #57

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

MarkSonghurst
Copy link
Contributor

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:

  1. 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.

  2. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant