From 763f9ad732d9d03a7bc4e4d8e38f66c7e366fe71 Mon Sep 17 00:00:00 2001 From: bhowe34 <30811239+bhowe34@users.noreply.github.com> Date: Wed, 8 Jun 2022 16:54:19 -0500 Subject: [PATCH] pass context to postgres queries (#15866) * pass context to postgres queries * add changelog * Update changelog/15866.txt Co-authored-by: Alexander Scheel Co-authored-by: Alexander Scheel --- changelog/15866.txt | 3 +++ physical/postgresql/postgresql.go | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 changelog/15866.txt diff --git a/changelog/15866.txt b/changelog/15866.txt new file mode 100644 index 000000000..384762e11 --- /dev/null +++ b/changelog/15866.txt @@ -0,0 +1,3 @@ +```release-note:improvement +physical/postgresql: pass context to queries to propagate timeouts and cancellations on requests. +``` \ No newline at end of file diff --git a/physical/postgresql/postgresql.go b/physical/postgresql/postgresql.go index b7b1d072b..748399924 100644 --- a/physical/postgresql/postgresql.go +++ b/physical/postgresql/postgresql.go @@ -244,7 +244,7 @@ func (m *PostgreSQLBackend) Put(ctx context.Context, entry *physical.Entry) erro parentPath, path, key := m.splitKey(entry.Key) - _, err := m.client.Exec(m.put_query, parentPath, path, key, entry.Value) + _, err := m.client.ExecContext(ctx, m.put_query, parentPath, path, key, entry.Value) if err != nil { return err } @@ -261,7 +261,7 @@ func (m *PostgreSQLBackend) Get(ctx context.Context, fullPath string) (*physical _, path, key := m.splitKey(fullPath) var result []byte - err := m.client.QueryRow(m.get_query, path, key).Scan(&result) + err := m.client.QueryRowContext(ctx, m.get_query, path, key).Scan(&result) if err == sql.ErrNoRows { return nil, nil } @@ -285,7 +285,7 @@ func (m *PostgreSQLBackend) Delete(ctx context.Context, fullPath string) error { _, path, key := m.splitKey(fullPath) - _, err := m.client.Exec(m.delete_query, path, key) + _, err := m.client.ExecContext(ctx, m.delete_query, path, key) if err != nil { return err } @@ -300,7 +300,7 @@ func (m *PostgreSQLBackend) List(ctx context.Context, prefix string) ([]string, m.permitPool.Acquire() defer m.permitPool.Release() - rows, err := m.client.Query(m.list_query, "/"+prefix) + rows, err := m.client.QueryContext(ctx, m.list_query, "/"+prefix) if err != nil { return nil, err }