Skip to content

Commit

Permalink
Fix login timeout segmentation faults (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvogelzang authored May 20, 2021
1 parent c1c9864 commit af74fe4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## (unreleased)

* Fix compilation errors for Amazon Linux 1. Fixes #495.
* Fix segfault for login timeouts

## 2.1.4

Expand Down
7 changes: 4 additions & 3 deletions ext/tiny_tds/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,14 @@ int tinytds_err_handler(DBPROCESS *dbproc, int severity, int dberr, int oserr, c
but we don't ever want to automatically retry. Instead have the app
decide what to do.
*/
if (userdata->timing_out) {
if (userdata && userdata->timing_out) {
return INT_CANCEL;
}
else {
// userdata will not be set if hitting timeout during login so check for it first
if (userdata) {
userdata->timing_out = 1;
return_value = INT_TIMEOUT;
}
return_value = INT_TIMEOUT;
cancel = 1;
break;

Expand Down
18 changes: 18 additions & 0 deletions test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,24 @@ class ClientTest < TinyTds::TestCase
end
end

it 'raises TinyTds exception with login timeout' do
skip if ENV['CI'] && ENV['APPVEYOR_BUILD_FOLDER'] # only CI using docker
begin
action = lambda do
Toxiproxy[:sqlserver_test].toxic(:timeout, timeout: 0).apply do
new_connection login_timeout: 1, port: 1234
end
end
assert_raise_tinytds_error(action) do |e|
assert_equal 20003, e.db_error_number
assert_equal 6, e.severity
assert_match %r{timed out}i, e.message, 'ignore if non-english test run'
end
ensure
assert_new_connections_work
end
end

it 'raises TinyTds exception with wrong :username' do
skip if ENV['CI'] && sqlserver_azure? # Some issue with db_error_number.
options = connection_options :username => 'willnotwork'
Expand Down

0 comments on commit af74fe4

Please sign in to comment.