Uploaded image for project: 'MariaDB Connector/Python'
  1. MariaDB Connector/Python
  2. CONPY-360

Add server-side statement timeouts: query_timeout (connection) and timeout= (per execute())

    XMLWordPrintable

Details

    • New Feature
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None
    • 2.0.0-rc3
    • None
    • None

    Description

      Client-side timeouts don't work for async: socket.settimeout() is a no-op on the non-blocking socket, and asyncio.wait_for() only cancels the client coroutine while the server keeps executing the statement (and leaves the connection desynced). So socket_timeout/read_timeout/write_timeout aren't meaningful for async.
      Enforce timeouts on the server instead, at two levels:

      1. Connection-level query_timeout= applied once after connect as the default for every statement on the connection:

      MariaDB:

      SET SESSION max_statement_time = <query_timeout>
      

      (seconds)
      MySQL:

      SET SESSION max_execution_time = <query_timeout Ă— 1000>
      

      (ms)

      2. Per-statement timeout= on execute()/executemany(), overrides query_timeout for a single statement:

      MariaDB: prefix the statement with

      SET STATEMENT max_statement_time=<timeout> FOR <statement>
      

      : one round-trip, works for any statement type.
      MySQL: no usable generic per-statement mechanism (MAX_EXECUTION_TIME is a SELECT-only optimizer hint that requires rewriting the query), so per-statement timeout is not supported on MySQL.
      The server aborts overrunning statements itself with a clean error, so the connection stays usable. Works for both sync and async.

      units differ: MariaDB seconds, MySQL ms

      MySQL max_execution_time covers read-only SELECT only, so on MySQL the timeout is effectively SELECT-only and the per-statement override is unavailable.

      Attachments

        Activity

          People

            georg Georg Richter
            diego dupin Diego Dupin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.