Skip to content

Commit 88495ce

Browse files
Pass context to async tasks to keep context fields intact (#8320)
* pass context to async tasks to keep context fields intact * remove redundant comment
1 parent 0443e9e commit 88495ce

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pkg/catalog/catalog.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -2296,8 +2296,8 @@ func (c *Catalog) GetRange(ctx context.Context, repositoryID, rangeID string) (g
22962296
return c.Store.GetRange(ctx, repository, graveler.RangeID(rangeID))
22972297
}
22982298

2299-
func (c *Catalog) importAsync(repository *graveler.RepositoryRecord, branchID, importID string, params ImportRequest, logger logging.Logger) error {
2300-
ctx, cancel := context.WithCancel(context.Background()) // Need a new context for the async operations
2299+
func (c *Catalog) importAsync(ctx context.Context, repository *graveler.RepositoryRecord, branchID, importID string, params ImportRequest, logger logging.Logger) error {
2300+
ctx, cancel := context.WithCancel(ctx)
23012301
defer cancel()
23022302

23032303
importManager, err := NewImport(ctx, cancel, logger, c.KVStore, repository, importID)
@@ -2419,7 +2419,9 @@ func (c *Catalog) Import(ctx context.Context, repositoryID, branchID string, par
24192419
// Run import
24202420
go func() {
24212421
logger := c.log(ctx).WithField("import_id", id)
2422-
err = c.importAsync(repository, branchID, id, params, logger)
2422+
// Passing context.WithoutCancel to avoid canceling the import operation when the wrapping Import function returns,
2423+
// and keep the context's fields intact for next operations (for example, PreCommitHook runs).
2424+
err = c.importAsync(context.WithoutCancel(ctx), repository, branchID, id, params, logger)
24232425
if err != nil {
24242426
logger.WithError(err).Error("import failure")
24252427
}

0 commit comments

Comments
 (0)