-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
return errors in favor of panicking, when possible
This commit changes copyist to instead return *sessionError via the sql driver in favor of panicking. Note in some cases, namely proxyRows.Columns, copyist will still panic as the proper behavior is otherwise unclear. Most usecases will encounter an error either before or after calling .Columns, so it is unlikely for users to encounter this panic. Returning errors instead of panicking fixes deadlocks that can occur when a driver.Conn is returning a driver.Rows inside of a transaction that recovers panics. Namely, cockroach-go [1]. A panic within a SQL Driver will cause the connections read mutex to NOT be unlocked as control should have been passed down to the sql.Rows (see queryDC in sql/sql.go). When the transaction helper method attempts to execute tx.Rollback, it will deadlock upon attempting to acquire the mutex. ``` // Cancel the Tx to release any active R-closemu locks. // This is safe to do because tx.done has already transitioned // from 0 to 1. Hold the W-closemu lock prior to rollback // to ensure no other connection has an active query. tx.cancel() tx.closemu.Lock() tx.closemu.Unlock() ``` Note that similar behavior would be encountered if instead attempting to call .Close on the Conn object. Users should be able to make use of transaction helpers that recover panics as behavior may become unpredictable within system that recover the panic elsewhere such as an HTTP server. Repositories under the cockroachdb organization should also work well together. [1] https://github.com/cockroachdb/cockroach-go/blob/master/crdb/common.go#L40
- Loading branch information
Showing
12 changed files
with
203 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.