Skip to content

Commit

Permalink
Pass context to async tasks to keep context fields intact (#8320)
Browse files Browse the repository at this point in the history
* pass context to async tasks to keep context fields intact

* remove redundant comment
  • Loading branch information
Jonathan-Rosenberg authored Oct 30, 2024
1 parent 0443e9e commit 88495ce
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -2296,8 +2296,8 @@ func (c *Catalog) GetRange(ctx context.Context, repositoryID, rangeID string) (g
return c.Store.GetRange(ctx, repository, graveler.RangeID(rangeID))
}

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

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

0 comments on commit 88495ce

Please sign in to comment.