From 84000524695d5834deef2374d24769210961bcf9 Mon Sep 17 00:00:00 2001 From: RiceChuan Date: Tue, 10 Dec 2024 17:22:58 +0800 Subject: [PATCH] refactor: In functions like ListOffChainData and GetMissingBatchKeys, although defer rows.Close() is used, if QueryxContext fails, rows will be nil. Calling defer rows.Close() in this case can trigger a panic. Signed-off-by: RiceChuan --- db/db.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/db/db.go b/db/db.go index 05144fa..5428f1b 100644 --- a/db/db.go +++ b/db/db.go @@ -262,8 +262,9 @@ func (db *pgDB) ListOffChainData(ctx context.Context, keys []common.Hash) ([]typ if err != nil { return nil, err } - - defer rows.Close() + if rows != nil { + defer rows.Close() + } type row struct { Key string `db:"key"`