Skip to content

Context not propagated to snowflakeFileTransferAgent on PUT command; cancellation is not supported #1028

@joellubi

Description

@joellubi

Context cancellation works for other queries executed using conn.ExecContext(), but is ignored for PUT/GET commands because it is not propagated any further than the snowflakeConn.processFileTransfer() method.

  1. What version of GO driver are you using?
    github.com/snowflakedb/gosnowflake v1.7.1

  2. What operating system and processor architecture are you using?
    macOS 14.1.1 x86_64

  3. What version of GO are you using?
    go version go1.21.5 darwin/amd64

  4. Server version:
    8.1.0

  5. What did you do?

package main

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

	"github.com/snowflakedb/gosnowflake"
)

func main() {
	cfg := &gosnowflake.Config{
		// Redacted
	}

	dsn, err := gosnowflake.DSN(cfg)
	if err != nil {
		log.Fatal(err)
	}

	db, err := sql.Open("snowflake", dsn)
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	conn, err := db.Conn(ctx)
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	stageName := "my_temp_stage"
	createStageQuery := "CREATE OR REPLACE STAGE my_temp_stage" + stageName
	putQuery := "PUT file:///path/to/test.parquet @" + stageName + " OVERWRITE=true"

	_, err = conn.ExecContext(ctx, createStageQuery)
	if err != nil {
		log.Fatal(err)
	}

	go func() {
		time.Sleep(10 * time.Second)
		log.Println("Canceled")
		cancel()
	}()

	log.Println("Starting PUT upload")
	_, err = conn.ExecContext(ctx, putQuery)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Completed PUT upload")
}
  1. What did you expect to see?

Expected Logs

% go run .
2024/01/10 21:11:22 Starting PUT upload
2024/01/10 21:11:32 Canceled
2024/01/10 21:11:32 context canceled
exit status 1

Actual Logs

% go run .
2024/01/10 21:11:22 Starting PUT upload
2024/01/10 21:11:32 Canceled
2024/01/10 21:12:36 Completed PUT upload
  1. Can you set logging to DEBUG and collect the logs?

    https://community.snowflake.com/s/article/How-to-generate-log-file-on-Snowflake-connectors

Yes, if it will help. But it's clear in the code that ctx is not passed all the way down to the upload methods.

  1. What is your Snowflake account identifier, if any? (Optional)

Metadata

Metadata

Labels

bugErroneous or unexpected behaviourstatus-fixed_awaiting_releaseThe issue has been fixed, its PR merged, and now awaiting the next release cycle of the connector.status-triage_doneInitial triage done, will be further handled by the driver team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions