Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/postgres/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ func (c *Client) RevokeAllGrantsFromRole(ctx context.Context, roleName string) e
l.Warn("error querying types", zap.String("schema", schema), zap.Error(err))
revokeError = errors.Join(revokeError, err)
} else {
defer typeRows.Close()

for typeRows.Next() {
var typeName string
if err := typeRows.Scan(&typeName); err != nil {
Expand All @@ -290,6 +288,11 @@ func (c *Client) RevokeAllGrantsFromRole(ctx context.Context, roleName string) e
revokeError = errors.Join(revokeError, err)
}
}
if err := typeRows.Err(); err != nil {
l.Warn("error iterating types", zap.String("schema", schema), zap.Error(err))
revokeError = errors.Join(revokeError, err)
}
typeRows.Close()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Suggestion: Pre-existing: typeRows.Err() is not checked after the for typeRows.Next() loop. If the iterator stops due to a network or driver error (rather than exhausting rows), the error is silently lost. Consider adding a typeRows.Err() check before Close().

Suggested change
typeRows.Close()
typeRows.Close()
if err := typeRows.Err(); err != nil {
l.Warn("error iterating types", zap.String("schema", schema), zap.Error(err))
revokeError = errors.Join(revokeError, err)
}

}

revokeSchemaQuery := fmt.Sprintf("REVOKE ALL ON SCHEMA %s FROM %s", sanitizedSchema, sanitizedRoleName)
Expand Down
Loading