Commit 36ea8b1
fix: avoid EEXIST on race condition in createDirRecursively and copyFolderRecursiveSync (#154)
Replace custom recursive directory creation with built-in recursive mkdir in
node addon loading
When multiple packaged applications try to start simultaneously, they can
encounter race conditions when creating temporary directories for loading native
node addons. This manifests as an "EEXIST" error when calling `mkdirSync()`.
The issue occurs in the native module loading code path where pkg needs to
extract native addons to a temporary location before they can be loaded via
`process.dlopen()`. The current implementation uses a custom
`createDirRecursively()` function that has a race condition - it checks if a
directory exists and then tries to create it, but another process could create
the directory between the check and creation.
Node.js has built-in support for recursive directory creation via the
`recursive: true` option in `mkdirSync()`. This handles race conditions properly
- if the directory already exists, it will not throw an error. This is exactly
what we need.
Co-authored-by: Daniel Lando <daniel.sorridi@gmail.com>1 parent b46f5cb commit 36ea8b1
1 file changed
+2
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | | - | |
189 | | - | |
190 | | - | |
| 188 | + | |
191 | 189 | | |
192 | 190 | | |
193 | 191 | | |
| |||
249 | 247 | | |
250 | 248 | | |
251 | 249 | | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | 250 | | |
260 | 251 | | |
261 | 252 | | |
| |||
2218 | 2209 | | |
2219 | 2210 | | |
2220 | 2211 | | |
2221 | | - | |
| 2212 | + | |
2222 | 2213 | | |
2223 | 2214 | | |
2224 | 2215 | | |
| |||
0 commit comments