-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moving context.WithoutCancel
outside defer.
#17260
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #17260 +/- ##
==========================================
- Coverage 65.39% 65.38% -0.02%
==========================================
Files 1187 1187
Lines 106239 106250 +11
Branches 2546 2546
==========================================
- Hits 69480 69475 -5
- Misses 31477 31493 +16
Partials 5282 5282
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
The change makes sense to me. Is the reasoning the following? func (svc *Service) GetCampaignReader(ctx context.Context, campaign *fleet.DistributedQueryCampaign) (<-chan interface{}, context.CancelFunc, error) {
[...]
campaign.Status = fleet.QueryRunning
if err := svc.ds.SaveDistributedQueryCampaign(ctx, campaign); err != nil {
|
It seems this change fixes the issue. I can reproduce the issue in
@xpkoala @getvictor feel free to test. |
…queries if ctx canceled
err = svc.liveQueryStore.RunQuery(strconv.Itoa(int(campaign.ID)), queryString, hostIDs) | ||
if err != nil { | ||
return nil, ctxerr.Wrap(ctx, err, "run query") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the bugs I reproduced was caused by context being canceled when executing svc.ds. CountHostsInTargets
(which meant leaving a live query orphaned in Redis). So as a simple fix to avoid refactoring given the available time I'm moving this down.
PS: Such live query was removed from Redis after running cleanups_then_aggregation
followed by frequent_cleanups
. But it's probably not optimal as it can be left orphaned for 1 hour and 15 minutes or so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lucasmrod Any predicted side effects to this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that I can think of. (The swaped operations are independent.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
#17197 Fixing orphaned live queries when context is canceled Co-authored-by: Lucas Rodriguez <lucas@fleetdm.com>
#17197
changes/
ororbit/changes/
.See Changes files for more information.
SELECT *
is avoided, SQL injection is prevented (using placeholders for values in statements)cmd/osquery-perf
for new osquery data ingestion features.