From a05d6ed03239728d9997b1f9e572b2c99b5e0e12 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Mon, 23 Nov 2020 21:31:04 -0800 Subject: [PATCH] fix #556: guard "ProbeResolvePackageAsRelative" --- CHANGELOG.md | 14 ++++++++++++++ internal/resolver/resolver.go | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d178bff1243..8c7ea651c4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## Unreleased + +* Fix a concurrency bug caused by an error message change ([#556](https://github.com/evanw/esbuild/issues/556)) + + An improvement to the error message for path resolution was introduced in version 0.8.12. It detects when a relative path is being interpreted as a package path because you forgot to start the path with `./`: + + ``` + > src/posts/index.js: error: Could not resolve "PostCreate" (use "./PostCreate" to import "src/posts/PostCreate.js") + 2 │ import PostCreate from 'PostCreate'; + ╵ ~~~~~~~~~~~~ + ``` + + This is implemented by re-running path resolution for package path resolution failures as a relative path instead. Unfortunately, this second path resolution operation wasn't guarded by a mutex and could result in concurrency bugs. This issue only occurs when path resolution fails. It is fixed in this release. + ## 0.8.13 * Assigning to a `const` symbol is now an error when bundling diff --git a/internal/resolver/resolver.go b/internal/resolver/resolver.go index a0913234736..3da6ae530c1 100644 --- a/internal/resolver/resolver.go +++ b/internal/resolver/resolver.go @@ -253,6 +253,10 @@ func (r *resolver) ResolveAbs(absPath string) *ResolveResult { func (r *resolver) ProbeResolvePackageAsRelative(sourceDir string, importPath string, kind ast.ImportKind) *ResolveResult { absPath := r.fs.Join(sourceDir, importPath) + + r.mutex.Lock() + defer r.mutex.Unlock() + if pair, ok := r.loadAsFileOrDirectory(absPath, kind); ok { return r.finalizeResolve(ResolveResult{PathPair: pair}) }