Skip to content

Commit 19ec98c

Browse files
eelcoarcanis
authored andcommitted
Don’t call release with an exit code (#6981)
* Don’t call `release` with an exit code The `release` signature is incorrect, because its first argument is a callback function that will be called when the release is done. By attaching it to the `run()` promise however, release will be called with the exit code as argument. When the exit code is `1`, the code will crash. This is very rare, but we’re seeing this when calling yarn from another node process (and possibly killing it too soon): ``` <redacted>/node_modules/yarn/lib/cli.js:78119 callback(); ^ TypeError: callback is not a function at options.fs.rmdir (<redacted>/node_modules/yarn/lib/cli.js:78119:9) at FSReqWrap.oncomplete (fs.js:141:20) ``` * Only resolve after releasing is done, improve type of `release`. Note that this slightly violates the type of runEventuallyWithFile, as the Promised resolved by the release callback might return an Error object. But since this error was also not handled before, it’s out of scope for the fix of this patch.
1 parent 65e198d commit 19ec98c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/cli/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export async function main({
291291
const runEventuallyWithFile = (mutexFilename: ?string, isFirstTime?: boolean): Promise<void> => {
292292
return new Promise(resolve => {
293293
const lockFilename = mutexFilename || path.join(config.cwd, constants.SINGLE_INSTANCE_FILENAME);
294-
lockfile.lock(lockFilename, {realpath: false}, (err: mixed, release: () => void) => {
294+
lockfile.lock(lockFilename, {realpath: false}, (err: mixed, release: (() => void) => void) => {
295295
if (err) {
296296
if (isFirstTime) {
297297
reporter.warn(reporter.lang('waitingInstance'));
@@ -303,7 +303,7 @@ export async function main({
303303
onDeath(() => {
304304
process.exitCode = 1;
305305
});
306-
resolve(run().then(release));
306+
resolve(run().then(() => new Promise(resolve => release(resolve))));
307307
}
308308
});
309309
});

0 commit comments

Comments
 (0)