Skip to content

Go program using context.WithTimeout with readonly db failed. #1681

@NamanMahor

Description

@NamanMahor

Observed

  1. For read only db like play.clickhouse.com when go program uses context.WithTimeout clickhouse-go/v2 fails with:
    query failed: code: 164, message: Cannot modify 'max_execution_time' setting in readonly mode
  2. The same query works fine in clickhouse client CLI:
clickhouse client  --host play.clickhouse.com --port 9440 --secure --user play

play-apj :) SET max_execution_time = 60;

SET max_execution_time = 60

Query id: 24593fa6-b14c-464d-981d-1eb31b1f8315

Ok.
play-apj :) show tables;

SHOW TABLES

Query id: fb81f174-2c0c-463c-bb71-498264929f4a

    ┌─name────────────────────────┐
 1. │ actors                      │

Expected behaviour

Should able to query read only db with context.WithTimeout in go

Code example

package main

import (
	"context"
	"database/sql"
	"fmt"
	"log"
	"time"

	_ "github.com/ClickHouse/clickhouse-go/v2"
)

func main() {
	// 30-second context deadline
	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
	defer cancel()

	conn, err := sql.Open("clickhouse", "clickhouse://[email protected]:9440?secure=true")
	if err != nil {
		log.Fatalf("failed to open connection: %v", err)
	}
	defer conn.Close()

	// Verify connection
	if err := conn.PingContext(ctx); err != nil {
		log.Fatalf("failed to ping ClickHouse: %v", err)
	}

	rows, err := conn.QueryContext(ctx, "SHOW TABLES")
	if err != nil {
		log.Fatalf("query failed: %v", err)
	}
	defer rows.Close()

	fmt.Println("Tables:")
	for rows.Next() {
		var table string
		if err := rows.Scan(&table); err != nil {
			log.Fatalf("failed to scan row: %v", err)
		}
		fmt.Println(" -", table)
	}

	if err := rows.Err(); err != nil {
		log.Fatalf("row iteration error: %v", err)
	}
}

Error log

query failed: code: 164, message: Cannot modify 'max_execution_time' setting in readonly mode

Details

Environment

  • clickhouse-go version: v2.40.3
  • Interface: ClickHouse API / database/sql compatible driver
  • Go version: 1.24.2
  • Operating system: macos
  • ClickHouse version: 25.9.1
  • Is it a ClickHouse Cloud? yes
  • ClickHouse Server non-default settings, if any: No
  • CREATE TABLE statements for tables involved: No
  • Sample data for all these tables, use clickhouse-obfuscator if necessary

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions