Skip to content

fix: add timeout to gRPC provider Cleanup to prevent scan hang#1748

Open
MaheshYadlapati wants to merge 1 commit into
snyk:mainfrom
MaheshYadlapati:fix/grpc-provider-cleanup-timeout
Open

fix: add timeout to gRPC provider Cleanup to prevent scan hang#1748
MaheshYadlapati wants to merge 1 commit into
snyk:mainfrom
MaheshYadlapati:fix/grpc-provider-cleanup-timeout

Conversation

@MaheshYadlapati

Copy link
Copy Markdown

Fixes #1653

Problem

driftctl scan hangs after completing all resource enumeration in certain
environments (containerised, slow networks, CI). The scan completes
successfully but the process never exits.

Root Cause

Cleanup() in enumeration/remote/terraform/provider.go calls
client.Close() as a bare blocking call with no timeout:

func (p *TerraformProvider) Cleanup() {
    for alias, client := range p.grpcProviders {
        logrus.WithFields(...).Debug("Closing gRPC client")
        client.Close()  // blocks indefinitely
    }
}

The debug output from affected users confirms the scan completes and
reaches "Closing gRPC client alias=eu-north-1" — the hang is on that
call in environments where gRPC shutdown does not return cleanly.

Fix

Wrap client.Close() in a goroutine with a 5-second timeout. If the
close does not complete within the timeout, a warning is logged and
execution continues rather than blocking forever.

No new imports required — time and plugin are already imported.

Testing

Existing test suite unchanged. The fix is isolated to the shutdown path
and does not affect any resource enumeration or drift detection logic.

@MaheshYadlapati MaheshYadlapati requested a review from a team as a code owner May 24, 2026 10:10
@CLAassistant

CLAassistant commented May 24, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@snyk-io

snyk-io Bot commented May 24, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@MaheshYadlapati MaheshYadlapati force-pushed the fix/grpc-provider-cleanup-timeout branch from 326bfbb to 837db65 Compare May 24, 2026 10:13
@MaheshYadlapati

Copy link
Copy Markdown
Author

Hi team, raised this PR to address #1653. @MaraDascalu01, would really appreciate a review and approval when you get a chance.

@MaheshYadlapati

Copy link
Copy Markdown
Author

@MaraDascalu01 , Please review and approve the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

driftctl hangs.

2 participants