Closed joellubi closed 2 months ago
hi and thank you for raising this issue with us; additionally providing all these details and the reproduction is very much appreciated ! we'll take a look
hi and thank you for raising this issue with us; additionally providing all these details and the reproduction is very much appreciated ! we'll take a look
Any update @sfc-gh-dszmolka ?
I'm keeping all issues updated when there's progress on them - at this moment, i have no update. Issues are addressed by their respective teams in terms of the impact they have. If this issue requires more attention and perhaps causing bigger impact for your company using Snowflake, please raise it with Snowflake Support too.
This repo is constantly monitored, however we cannot guarantee any specific timeline for resolution in advance. Thank you for your understanding!
https://github.com/snowflakedb/gosnowflake/pull/1196 merged - thank you for the contribution! will be released with the next upcoming driver release
released with gosnowflake v.1.11.1
Please answer these questions before submitting your issue. In order to accurately debug the issue this information is required. Thanks!
What version of GO driver are you using?
github.com/snowflakedb/gosnowflake v1.10.1
What operating system and processor architecture are you using?
What version of GO are you using? run
go version
in your consoleServer version:
8.27.1
What did you do?
If a
*sql.DB
instance is opened withsql.OpenDB(connector)
, then cancelling the context provided todb.QueryContext
after the query has completed will result in warnings getting logged that the context is already closed when "recycling" the connection. I've reproduced a minimal example below, but the real-world scenario this comes up in is iferrgroup
is used to dispatch multiple queries concurrently. Once youWait()
for the group to finish, the group's context is cancelled. The problem is that the driver currently attempts to reuse this context in the call todefer db.Close()
later when the function exits.Based on my investigation, this seems like it has to do with the db connection pooling that Go's
database/sql
provides automatically. If you uncomment the linedb.SetMaxIdleConns(0)
, then the error does not occur. I believe this is because it prevents Go from caching the connection.In order for
database/sql
connections to be persist-able within the cache, they should not store the context from the query that spawned them since it may have a shorter lifetime than the connection if it is reused. The docs indicate this as well:import ( "context" "database/sql" "fmt" "log"
)
var uri = "REDACTED"
func main() { ctxCancel, cancel := context.WithCancel(context.Background())
}
func printQueryResult(ctx context.Context, db *sql.DB, query string) error { rows, err := db.QueryContext(ctx, query) if err != nil { return err } defer rows.Close()
}
go run main.go hello
go run main.go hello ERRO[0000]connection.go:275 gosnowflake.(*snowflakeConn).Close context canceled