Skip to content

Commit

Permalink
Fix Situation Where Build Can Hang Indefinitely (#11881)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Apr 14, 2020
1 parent 4e6d6d2 commit 841cd6c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,39 @@ export default class TaskRunner {
const done = () => step(index, result)
if (cachePath) {
writeFileP(cachePath, JSON.stringify(result), 'utf8')
.then(done)
.catch(done)
// This is important to stay as `.then(fn1, fn2)` and not
// `.then(fn1).catch(fn2)` so that we don't double-invoke `step`
// when `done` emits an error.
.then(done, done)
.catch(err => {
// Abort task on internal error (`done` failed). This can
// happen when users have a bad `package-lock.json` with an
// invalid webpack version, etc:
callback(err)
})
}
} catch (error) {
step(index, { error })
}
}

if (this.cacheDir) {
readFileP(cachePath, 'utf8')
.then(data => step(index, JSON.parse(data)))
.catch(() => enqueue())
// This is important to stay as `.then(fn1, fn2)` and not
// `.then(fn1).catch(fn2)` so that we don't double-invoke `step` when
// `step` emits an error.
readFileP(cachePath, 'utf8').then(
data => {
try {
step(index, JSON.parse(data))
} catch (err) {
// Abort task on internal error (`done` failed). This can happen
// when users have a bad `package-lock.json` with an invalid
// webpack version, etc:
callback(err)
}
},
() => enqueue()
)
} else {
enqueue()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import stringHash from 'next/dist/compiled/string-hash'
import { SourceMapConsumer } from 'next/dist/compiled/source-map'
import { SourceMapSource, RawSource } from 'webpack-sources'
import { RequestShortener } from 'webpack'
import RequestShortener from 'webpack/lib/RequestShortener'
import TaskRunner from './TaskRunner'

const warningRegex = /\[.+:([0-9]+),([0-9]+)\]/
Expand Down Expand Up @@ -204,8 +204,11 @@ export class TerserPlugin {

taskRunner.run(tasks, (tasksError, results) => {
if (tasksError) {
compilation.errors.push(tasksError)

try {
taskRunner.exit()
} finally {
callback(tasksError)
}
return
}

Expand Down

0 comments on commit 841cd6c

Please sign in to comment.