mod: defer Unlock to avoid deadlocks in the pkg manager

Signed-off-by: Sam Alba <samalba@users.noreply.github.com>
This commit is contained in:
Sam Alba 2021-11-08 17:29:33 -08:00
parent 6acc7e2c4d
commit 1dd538e729

View File

@ -41,6 +41,8 @@ func Install(ctx context.Context, workspace, repoName, versionConstraint string)
return nil, err
}
defer fileLock.Unlock()
err = modfile.install(ctx, require)
if err != nil {
return nil, err
@ -50,10 +52,6 @@ func Install(ctx context.Context, workspace, repoName, versionConstraint string)
return nil, err
}
if err := fileLock.Unlock(); err != nil {
return nil, err
}
return require, nil
}
@ -98,6 +96,8 @@ func Update(ctx context.Context, workspace, repoName, versionConstraint string)
return nil, err
}
defer fileLock.Unlock()
updatedRequire, err := modfile.updateToLatest(ctx, require)
if err != nil {
return nil, err
@ -107,10 +107,6 @@ func Update(ctx context.Context, workspace, repoName, versionConstraint string)
return nil, err
}
if err := fileLock.Unlock(); err != nil {
return nil, err
}
return updatedRequire, nil
}