-
Notifications
You must be signed in to change notification settings - Fork 550
Use vio_is_connected to check connected state #1022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
ba6bb52
f52cb3b
914f56b
53ce628
37fc49d
b355917
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,8 @@ static ID intern_brackets, intern_merge, intern_merge_bang, intern_new_with_args | |
} | ||
|
||
#if defined(HAVE_MYSQL_NET_VIO) || defined(HAVE_ST_NET_VIO) | ||
#define CONNECTED(wrapper) (wrapper->client->net.vio != NULL && wrapper->client->net.fd != -1) | ||
my_bool vio_is_connected(Vio *vio); | ||
#define CONNECTED(wrapper) (wrapper->client->net.vio != NULL && wrapper->client->net.fd != -1 && vio_is_connected(wrapper->client->net.vio)) | ||
#elif defined(HAVE_MYSQL_NET_PVIO) || defined(HAVE_ST_NET_PVIO) | ||
#define CONNECTED(wrapper) (wrapper->client->net.pvio != NULL && wrapper->client->net.fd != -1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add the |
||
#endif | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -342,6 +342,19 @@ def run_gc | |
@client.close | ||
expect(@client.closed?).to eql(true) | ||
end | ||
|
||
it "should detect a closed connection" do | ||
connection_id = @client.thread_id | ||
Thread.new do | ||
sleep(0.1) | ||
Mysql2::Client.new(DatabaseCredentials['root']).tap do |supervisor| | ||
supervisor.query("KILL #{connection_id}") | ||
end.close | ||
end | ||
expect(@client.query("SELECT 1").first["1"]).to eql(1) | ||
sleep(0.2) | ||
expect(@client.closed?).to be true | ||
end | ||
end | ||
|
||
it "should not try to query closed mysql connection" do | ||
|
@@ -573,7 +586,7 @@ def run_gc | |
end | ||
expect do | ||
@client.query("SELECT SLEEP(1)") | ||
end.to raise_error(Mysql2::Error, /Lost connection to MySQL server/) | ||
end.to raise_error(Mysql2::Error, 'MySQL client is not connected') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the different error text? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's because we're validating the connection before executing the query (and it's now failing) and it raises with this error text. |
||
|
||
if RUBY_PLATFORM !~ /mingw|mswin/ | ||
expect do | ||
|
@@ -582,6 +595,19 @@ def run_gc | |
end | ||
end | ||
|
||
it "should detect a closed connection" do | ||
connection_id = @client.thread_id | ||
Thread.new do | ||
sleep(0.1) | ||
Mysql2::Client.new(DatabaseCredentials['root']).tap do |supervisor| | ||
supervisor.query("KILL #{connection_id}") | ||
end.close | ||
end | ||
expect(@client.query("SELECT 1").first["1"]).to eql(1) | ||
sleep(0.2) | ||
expect(@client.closed?).to be true | ||
end | ||
|
||
if RUBY_PLATFORM !~ /mingw|mswin/ | ||
it "should not allow another query to be sent without fetching a result first" do | ||
@client.query("SELECT 1", async: true) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this to a header file and add an autoconf test that checks if the header is available in the given client library (there are more client libraries than just libmysqlclient).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Yeah, there's some symbol resolution issues I'm seeing in CI. I'm going to add some autoconf-style checks to clean this up.