Skip to content

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

Open
@damianthe

Description

@damianthe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions