Skip to content
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

[BUG] Timeout does not apply when buffer is large #1091

Open
damianthe opened this issue Dec 9, 2019 · 2 comments
Open

[BUG] Timeout does not apply when buffer is large #1091

damianthe opened this issue Dec 9, 2019 · 2 comments

Comments

@damianthe
Copy link

damianthe commented Dec 9, 2019

While looking into making mysql2 support non-integer timeouts, @pushrax and I found a bug in the client.

There is a specific edge case where neither the do_query file descriptor timeout nor the MYSQL_OPT_READ_TIMEOUT apply.

The error can be reproduced by running a query that responds quickly with the first reply but fills the query response buffer, therefore taking a while to read.

As you can see from the run below, this causes the query the run successfully, despite going over the 1 second read timeout time.

Instructions to reproduce

Set the client configuration in the following test and run it.

  it "timeout overflow buffer timeout edge case" do
    client = Mysql2::Client.new(
      host: '<insert>',
      port: '<insert>',
      username: '<insert>',
      database: '<insert>',
      connect_timeout: 1,
      read_timeout: 1,
      write_timeout: 1,
    )

    client.query("CREATE TABLE IF NOT EXISTS test_table (c1 MEDIUMTEXT, c2 MEDIUMTEXT)")

    s = StringIO.new
    1500.times { s << "sdjsdjsdjssadaskdhasfhasjdhaskdjhasdjkhsadjkh" }
    3000.times do
    client.query("INSERT INTO test_table (c1, c2) VALUES ('#{s.string}', '#{s.string}')")
    end

    start_time = Time.now
    client.query("SELECT * from test_table")
    query_time = Time.now - start_time

    expect(query_time).to be <= 1.0
  ensure
    client.query("DROP TABLE IF EXISTS test_table")
  end

The result on my local machine:
image

@damianthe
Copy link
Author

cc @sodabrew

@jeremy
Copy link
Contributor

jeremy commented Nov 9, 2021

Looks like #807 / #962.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants