Skip to content

Commit 6fe63fa

Browse files
committed
Add worker thread hack
This adds a work-around to `rust#91979` (rust-lang/rust#91979) A segmentation fault is currently triggered on worker thread exit if: * Application runs with `atlaspack` on the main thread * Plugin on worker-thread imports `parcel/rust` The work-around is to force parcel native bindings to be loaded eagerly if available. Test Plan: test dev release Pull Request: #472
1 parent 3f44645 commit 6fe63fa

File tree

5 files changed

+39
-3
lines changed

5 files changed

+39
-3
lines changed

.changeset/tiny-knives-scream.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@atlaspack/core': patch
3+
---
4+
5+
Fix segmentation fault on exit on certain cases

packages/core/core/src/Atlaspack.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ import {
5858
fromProjectPathRelative,
5959
} from './projectPath';
6060
import {tracer} from '@atlaspack/profiler';
61-
import {setFeatureFlags, DEFAULT_FEATURE_FLAGS} from '@atlaspack/feature-flags';
61+
import {
62+
getFeatureFlag,
63+
setFeatureFlags,
64+
DEFAULT_FEATURE_FLAGS,
65+
} from '@atlaspack/feature-flags';
6266
import {AtlaspackV3, FileSystemV3} from './atlaspack-v3';
6367
import createAssetGraphRequestJS from './requests/AssetGraphRequest';
6468
import {createAssetGraphRequestRust} from './requests/AssetGraphRequestRust';
6569
import type {AssetGraphRequestResult} from './requests/AssetGraphRequest';
70+
import {loadRustWorkerThreadDylibHack} from './rustWorkerThreadDylibHack';
6671

6772
registerCoreWithSerializer();
6873

@@ -117,6 +122,10 @@ export default class Atlaspack {
117122
};
118123
setFeatureFlags(featureFlags);
119124

125+
if (getFeatureFlag('enableRustWorkerThreadDylibHack')) {
126+
loadRustWorkerThreadDylibHack();
127+
}
128+
120129
await initSourcemaps;
121130
await initRust?.();
122131

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// @flow strict-local
2+
3+
/**
4+
* This is a workaround for https://github.com/rust-lang/rust/issues/91979
5+
* when running atlaspack with parcel bindings, it is possible that the parcel
6+
* dylib will be loaded from a node worker thread, which causes a crash on exit.
7+
*
8+
* This is a workaround to ensure that the parcel dylib is loaded in the main
9+
* thread, which fixes the crash.
10+
*/
11+
export function loadRustWorkerThreadDylibHack() {
12+
try {
13+
// $FlowFixMe
14+
require('@parcel/rust'); // eslint-disable-line
15+
} catch (err) {
16+
/* ignore */
17+
}
18+
}

packages/core/feature-flags/src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export const DEFAULT_FEATURE_FLAGS: FeatureFlags = {
2020
inlineBundlesSourceMapFixes: false,
2121
conditionalBundlingNestedRuntime: false,
2222
patchProjectPaths: false,
23-
inlineStringReplacementPerf: false,
23+
enableRustWorkerThreadDylibHack: false,
24+
inlineStringReplacementPerf: true,
2425
};
2526

2627
let featureFlagValues: FeatureFlags = {...DEFAULT_FEATURE_FLAGS};

packages/core/feature-flags/src/types.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ export type FeatureFlags = {|
5858
* This feature is experimental and should not be used in production. It will used to test downloadble cache artefacts.
5959
*/
6060
patchProjectPaths: boolean,
61-
61+
/**
62+
* Enable loading of the parcel dylib in the main thread.
63+
*/
64+
enableRustWorkerThreadDylibHack: boolean,
6265
/**
6366
* Enables optimized inline string replacement perf for the packager.
6467
* Used heavily for inline bundles.

0 commit comments

Comments
 (0)