Unverified Commit 4e66e86f authored by Michelle Nguyen's avatar Michelle Nguyen Committed by Copybara
Browse files

Ensure db connections are closed when disabling plugin


Summary:
We were seeing some issues with db connections. Taking a look at recent plugin code shows a potential area where the connection may not be getting closed properly.
Defer in these cases aren't as ideal, since there are multiple db requests in a function. We just need to make sure we close the row if we're returning early due to an error.

Test Plan: existing tests pass

Reviewers: vihang

Reviewed By: vihang
Signed-off-by: default avatarMichelle Nguyen <michellenguyen@pixielabs.ai>

Differential Revision: https://phab.corp.pixielabs.ai/D11704

GitOrigin-RevId: 8d650e5e0221f48d678c4974d1cf5f18c5328bfa
parent d2edbc30
Showing with 7 additions and 4 deletions
+7 -4
......@@ -282,6 +282,7 @@ func (s *Server) createPresetScripts(ctx context.Context, txn *sqlx.Tx, orgID uu
return status.Errorf(codes.Internal, "Failed to fetch plugin")
}
defer rows.Close()
var plugin RetentionPlugin
if rows.Next() {
err := rows.StructScan(&plugin)
......@@ -312,7 +313,7 @@ func (s *Server) disableOrgRetention(ctx context.Context, txn *sqlx.Tx, orgID uu
if err != nil {
return status.Errorf(codes.Internal, "Failed to fetch scripts")
}
defer rows.Close()
for rows.Next() {
var id uuid.UUID
err = rows.Scan(&id)
......@@ -334,7 +335,7 @@ func (s *Server) disableOrgRetention(ctx context.Context, txn *sqlx.Tx, orgID uu
if err != nil {
return status.Errorf(codes.Internal, "Failed to fetch custom export scripts")
}
defer rows.Close()
for rows.Next() {
var id uuid.UUID
err = rows.Scan(&id)
......@@ -367,7 +368,7 @@ func (s *Server) updatePresetScripts(ctx context.Context, txn *sqlx.Tx, orgID uu
if err != nil {
return status.Errorf(codes.Internal, "Failed to fetch plugin")
}
defer rows.Close()
var plugin RetentionPlugin
if rows.Next() {
err := rows.StructScan(&plugin)
......@@ -585,6 +586,7 @@ func (s *Server) UpdateOrgRetentionPluginConfig(ctx context.Context, req *plugin
var customExportURL *string
var insecureTLS bool
enabled := false
defer rows.Close()
if rows.Next() {
enabled = true
err := rows.Scan(&origVersion, &origConfig, &customExportURL, &insecureTLS)
......@@ -603,6 +605,7 @@ func (s *Server) UpdateOrgRetentionPluginConfig(ctx context.Context, req *plugin
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to fetch plugin")
}
defer rows.Close()
var allowCustomExportURL bool
var allowInsecureTLS bool
if rows.Next() {
......@@ -967,7 +970,7 @@ func (s *Server) UpdateRetentionScript(ctx context.Context, req *pluginpb.Update
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to fetch script")
}
defer rows.Close()
if !rows.Next() {
return nil, status.Error(codes.NotFound, "script not found")
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment