Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
0381db7 to
511765e
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
d94d307 to
402304a
Compare
This comment has been minimized.
This comment has been minimized.
eb91fb0 to
dccddef
Compare
This comment has been minimized.
This comment has been minimized.
dccddef to
5984ccb
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5984ccb to
f9e02d6
Compare
This comment has been minimized.
This comment has been minimized.
f9e02d6 to
1d4c73a
Compare
This comment has been minimized.
This comment has been minimized.
1d4c73a to
8d03e26
Compare
This comment has been minimized.
This comment has been minimized.
8d03e26 to
efc5edd
Compare
This comment has been minimized.
This comment has been minimized.
efc5edd to
91dc563
Compare
This comment has been minimized.
This comment has been minimized.
91dc563 to
34f431c
Compare
This comment has been minimized.
This comment has been minimized.
| errorListCopy := append([]error{}, errorList...) | ||
| errorListMutex.Unlock() | ||
|
|
||
| finalExitCode = tearDown(ctx, signalError, errorListCopy, startTime, ua, cliAnalytics, networkAccess) |
There was a problem hiding this comment.
question: if teardown hangs (e.g. when making the analytics API call), can we still SIGINT the process? Or does teardownOnce prevent this? Basically, is it possible to be a hanging state?
There was a problem hiding this comment.
As mentioned before, I'm working on a solution.
| cliAnalytics.AddError(tempError) | ||
| } | ||
| } | ||
| if globalConfiguration.GetBool(configuration.PREVIEW_FEATURES_ENABLED) { |
There was a problem hiding this comment.
question(0): what's the reason for putting this behind preview features?
question(1): what's the condition for removing this?
There was a problem hiding this comment.
Q1: This could easily have side effects that I want to carefully roll out. Using preview only is a simple straight forward way to collect feedback from internal and preview usage in general.
Q2: That is a good question. I would say if we think it creates value and if concerns are mitigated.
|
suggestion: is it possible to write a test to validate this behaviour? |
34f431c to
63602e0
Compare
This comment has been minimized.
This comment has been minimized.
63602e0 to
bbac494
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
61855c0 to
a55a4e3
Compare
This comment has been minimized.
This comment has been minimized.
8439915 to
a6b802f
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
a6b802f to
856f008
Compare
This comment has been minimized.
This comment has been minimized.
856f008 to
0a239d7
Compare
This comment has been minimized.
This comment has been minimized.
chore: ensure to kill CLI processes
0a239d7 to
ad74501
Compare
PR Reviewer Guide 🔍
|
| func tearDown(ctx context.Context, err error, errorList []error, startTime time.Time, ua networking.UserAgentInfo, cliAnalytics analytics.Analytics, networkAccess networking.NetworkAccess) int { | ||
| // Create a context with timeout for teardown operations to ensure we don't hang indefinitely | ||
| teardownCtx, cancel := context.WithTimeout(ctx, teardownTimeout) |
There was a problem hiding this comment.
The context ctx here can happen to be already-cancelled as it is derived from the parent context. Testing locally, I saw this issue happening:
Here I suppose you should use a fresh context for tearing down:
teardownCtx, cancel := context.WithTimeout(context.Background(), teardownTimeout)Also, the context parameter we can use ctxCancel, updating the function signature:
func tearDown(ctx context.Context, ... -> func tearDown(ctxCancel context.CancelFunc, ...
in the calls of tearDown (L664 and L716), we provide ctxCancel:
finalExitCode = tearDown(ctxCancel, signalError, errorListCopy, startTime, ua, cliAnalytics, networkAccess)
...
finalExitCode = tearDown(ctxCancel, err, errorListCopy, startTime, ua, cliAnalytics, networkAccess)And after sendInstrumentation call (line 516) can terminate child processes:
sendInstrumentation(teardownCtx, globalEngine, cliAnalytics.GetInstrumentation(), globalLogger)
ctxCancel()i.e. instead of calling ctxCancel in line 655, we do it here after sendInstrumentation, wdyt?
There was a problem hiding this comment.
Thanks @danskmt ! Good catches! I marked the PR as draft as it is far from ready. There are plenty of local changes as well, so I prematurely marked this as to review. Sorry for that!
There was a problem hiding this comment.
No worries! Let me know when you want me to review it again.
Pull request was converted to draft
Pull Request Submission Checklist
What does this PR do?
Ensures instrumentation data is sent when the CLI is terminated by a signal (SIGINT/SIGTERM). Previously, if a user killed a running CLI command (e.g., via Ctrl+C), instrumentation data would be lost. This change:
PREVIEW_FEATURES_ENABLEDflag) that intercepts SIGINT/SIGTERM and runs teardown before exitingsync.Onceto ensure teardown runs exactly once, whether triggered by normal completion or signalNewTerminatedBySignalErrorfor proper error categorizationWhere should the reviewer start?
Start with
cliv2/cmd/cliv2/main.go:487-523for the new tearDown() function, then review the signal handling setup at lines 635-656.snyk/go-application-framework#578
How should this be manually tested?
with a developer build
snyk teston a large project)--debug) that instrumentation is sent before exitWhat's the product update that needs to be communicated to CLI users?
N/A - This is an internal improvement to telemetry reliability. No user-facing behavior changes.
Risk assessment (Low | Medium | High)?
Medium - Changes core CLI exit flow, but:
PREVIEW_FEATURES_ENABLEDflagsync.Onceto prevent double-executionAny background context you want to provide?
When users terminate CLI commands prematurely, we lose visibility into those interactions. This change improves our ability to understand CLI usage patterns and identify issues with long-running commands.