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

Query/Exec hangs when there are external network latency #119

Open
sharathjag opened this issue Feb 20, 2025 · 5 comments
Open

Query/Exec hangs when there are external network latency #119

sharathjag opened this issue Feb 20, 2025 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@sharathjag
Copy link

sharathjag commented Feb 20, 2025

query and exec calls hangs indefinitely when external network latency was introduced.

Steps to reproduce.

script:

import sql from "k6/x/sql";

// the actual database driver should be used instead of ramsql
import driver from "k6/x/sql/driver/mysql";

const db = sql.open(driver, "some-db");

export function setup() {
  db.exec(`
  CREATE TABLE IF NOT EXISTS roster
       (
         id INTEGER NOT NULL AUTOINCREMENT,
         given_name VARCHAR NOT NULL,
         family_name VARCHAR NOT NULL,
         PRIMARY KEY (ID)
       );
 `);
}

export function teardown() {
  db.close();
}

export default function () {
  let result = db.exec(`
    INSERT INTO roster_2
      (given_name, family_name)
    VALUES
      ('Peter', 'Pan'),
      ('Wendy', 'Darling'),
      ('Tinker', 'Bell'),
      ('James', 'Hook');
  `);
  console.log(`${result.rowsAffected()} rows inserted`);

  let rows = db.query("SELECT * FROM roster WHERE given_name = $1;", "Peter");
  for (const row of rows) {
    console.log(`${row.family_name}, ${row.given_name}`);
  }
}
  • start mysql locally.
  • ./k6 run --vus 10 --duration 60s ./example.js
  • kill -SIGSTOP 76699
  • Wait for query/vu to run indefinitely

We have a fix on our fork https://github.com/sharathjag/xk6-sql/blob/conn-options-with-timeouts/sql/module.go#L275
Happy to refine and open PR if the general direction makes sense. Please, keep me posted.

Also see: grafana/k6#3958 (comment)

@sharathjag
Copy link
Author

@szkiba I created this one as well.
Whenever you get a chance. Have a draft as well https://github.com/sharathjag/xk6-sql/blob/conn-options-with-timeouts/sql/module.go#L275
LMK, how you want us to proceed

@szkiba
Copy link
Contributor

szkiba commented Feb 21, 2025

@sharathjag , Yes, I saw that. Context handling and timeout require a bit more thought, so I didn't include it in the release. I'll continue to think about it.

@szkiba szkiba self-assigned this Feb 21, 2025
@szkiba szkiba added the enhancement New feature or request label Feb 21, 2025
@szkiba
Copy link
Contributor

szkiba commented Feb 21, 2025

related: #124

@sharathjag
Copy link
Author

agreed, it needs a little more thought.
I was debating b/w passing vu object to db, I didn't like it either.
May be add a module level method to get the context?

@szkiba
Copy link
Contributor

szkiba commented Feb 26, 2025

@sharathjag FYI v1.0.4 released.

Contains improved context handling and timeout handling:

Maybe v1.0.4 release solve this issue as well.

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

No branches or pull requests

2 participants