fix connection release if api function raises exception

the connections were not released correctly when
the function raised an exception. fix this by interception
each raise in the get_connection decorator, release the
connection, and re-raise the exception.