From 0c47afe424cd2ff6b25598f535dec5c5a01c17f1 Mon Sep 17 00:00:00 2001 From: Wanderson Policarpo Date: Wed, 13 May 2020 22:23:35 +0100 Subject: [PATCH 1/3] Raise error if client is unable to execute statement --- ext/tiny_tds/client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/tiny_tds/client.c b/ext/tiny_tds/client.c index a65208df..0756cd03 100644 --- a/ext/tiny_tds/client.c +++ b/ext/tiny_tds/client.c @@ -296,8 +296,8 @@ static VALUE rb_tinytds_execute(VALUE self, VALUE sql) { REQUIRE_OPEN_CLIENT(cwrap); dbcmd(cwrap->client, StringValueCStr(sql)); if (dbsqlsend(cwrap->client) == FAIL) { - rb_warn("TinyTds: dbsqlsend() returned FAIL.\n"); - return Qfalse; + rb_raise(cTinyTdsError, "failed to execute statement"); + return self; } cwrap->userdata->dbsql_sent = 1; result = rb_tinytds_new_result_obj(cwrap); From 5b96c72217534042b5691a8f6b4d612822aea707 Mon Sep 17 00:00:00 2001 From: Wanderson Policarpo Date: Tue, 6 Apr 2021 23:42:19 +0100 Subject: [PATCH 2/3] Add test case for when connection is dead and tiny_tds raises an error --- test/client_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/client_test.rb b/test/client_test.rb index 15a0421e..88ab5b23 100644 --- a/test/client_test.rb +++ b/test/client_test.rb @@ -132,6 +132,25 @@ class ClientTest < TinyTds::TestCase end end + it 'raises TinyTds exception when tcp socket is down' do + skip if ENV['CI'] && ENV['APPVEYOR_BUILD_FOLDER'] # only CI using docker + begin + client = new_connection timeout: 2, port: 1234 + assert_client_works(client) + action = lambda { client.execute("waitfor delay '00:00:01'").do } + + # Use toxiproxy to close the TCP socket immediately. + # We want TinyTds to fail to execute the statement and raise an error immediately. + Toxiproxy[:sqlserver_test].down do + assert_raise_tinytds_error(action) do |e| + assert_match %r{failed to execute statement}i, e.message, 'ignore if non-english test run' + end + end + ensure + assert_new_connections_work + end + end + it 'raises TinyTds exception with tcp socket network failure' do skip if ENV['CI'] && ENV['APPVEYOR_BUILD_FOLDER'] # only CI using docker begin From 1dcf19c1b2fbec91add34119242a88c137fb5ea2 Mon Sep 17 00:00:00 2001 From: aharpervc Date: Fri, 7 May 2021 14:01:19 -0400 Subject: [PATCH 3/3] squash: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 594e4298..eaad58bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Improve handling of network related timeouts * Fix error reporting when preceded by info message +* Raise error if client is unable to execute statement ## 2.1.3