wonderix / crystal-tds

MIT License
11 stars 2 forks source link

Raise `DB::ConnectionLost` error when an IO error occurs to enable the crystal-db database pool to automatically remove bad connections from the connection pool #16

Closed lachlan closed 9 months ago

lachlan commented 9 months ago

@wonderix This pull request changes the TDS driver to raise a DB:ConnectionLost error if an IO error occurs when reading or writing to the socket, which then closes the connection (because it's gone bad likely because the SQL Server or a firewall reset the connection without telling the client), and this makes sure the connection is removed from the crystal-db connection pool. Currently the bad TDS connection is put back in the pool and handed out again on the next borrow, which means the pool won't self heal and the bad connection will stall the application using the driver.

I also changed how the TDS::VERSION constant is set to use a macro which calls the shards version command to make sure the version aligns between the shard.yml and the code, because I noticed I previously forgot to update the code version when I updated the shard.yml version. This fixes that so we only ever have to update the shard.yml version and the code version will stay in sync.

And I also added a more detail to a lot of the other error messages to help with diagnosing issues, and if we are wrapping another exception then I add that as the cause when raising.

Thanks for your consideration!