create-react-app 在CI构建中使用TypeScript的Yarn构建上设置了大量的inotify监视器,

jtw3ybtb  于 20天前  发布在  React
关注(0)|答案(2)|浏览(14)

描述bug

fork-ts-checker-webpack-pluginwebpack 中在 react-scripts 中生成了很多 inotify watches。这与在 #7612 中描述的问题相似。
这会导致我们在使用 jenkins kubernetes plugin 运行的 jenkins ci kubernetes 集群中的不稳定和崩溃。多个 jenkins pipelines 可以同时分配在同一 kuberentes 节点上。与 create-react-app 构建一起分配的 pipelines 经常会因 inotify watches 用尽而出现错误消息,如 No space left on deviceUser limit of inotify watches reached,因为运行 inotify watches 用尽会触发 ENOSPC。
通过在主机操作系统中增加 fs.inotify.max_user_watches 来解决这个问题并不吸引人,因为这需要使用自定义镜像或部署守护程序集来设置限制。增加限制也可能会带来意想不到的后果,尤其是如果太多使用 create-react-app 运行在同一节点上的构建。
fork-ts-checker-webpack-plugin 中禁用 fork-ts-checker-webpack-pluginuseTypescriptIncrementalApi 可以解决这个问题。

你是否尝试恢复依赖项?

这是来自 npx create-react-app my-app --template typescript 容器的新鲜 node:12

你在哪本用户手册中搜索了哪些术语?

inotify watches, ci,增量构建

环境

node:12 容器中运行:

root@ec29fa0bba40:/my-app# npx create-react-app --info
npx: installed 67 in 3.957s

Environment Info:

  current version of create-react-app: 4.0.3
  running from /root/.npm/_npx/21966/lib/node_modules/create-react-app

  System:
    OS: Linux 4.9 Debian GNU/Linux 9 (stretch) 9 (stretch)
    CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
  Binaries:
    Node: 12.21.0 - /usr/local/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 6.14.11 - /usr/local/bin/npm
  Browsers:
    Chrome: Not Found
    Firefox: Not Found
  npmPackages:
    react: ^17.0.1 => 17.0.1 
    react-dom: ^17.0.1 => 17.0.1 
    react-scripts: 4.0.3 => 4.0.3 
  npmGlobalPackages:
    create-react-app: Not Found

重现步骤

假设你已经安装了 docker,以下命令将在 node:12 容器中重现问题。在基于 linux 的操作系统上,你也可以通过跟踪 inotify watches using the script below 的数量来重现问题。这些命令设置了一个干净的 npx create-react-app my-app --template typescript 示例应用程序,并在跟踪 inotify watches 数量的同时运行 yarn build。如果你然后应用补丁以禁用 useTypescriptIncrementalApi,那么在下一个 yarn build 时,监视器数量将保持为零。

# shell 1
docker run -e CI=true -it --rm --name=inotify-watches-demo --entrypoint=/bin/bash node:12
# shell 2
docker exec -it inotify-watches-demo bash -c "while true; do find /proc/*/fd -lname anon_inode:inotify    -printf '%hinfo/%f\n' 2>/dev/null |    xargs cat | grep -c '^inotify'; sleep 0.2; done"

# shell 1
npx create-react-app my-app --template typescript
cd my-app
yarn build
# watch the number of watches grow to 5497 in shell 2
# The number of watches grows to 5497 again if you re-run yarn build

## FIX ##
# shell 1
patch --forward node_modules/react-scripts/config/webpack.config.js   << EOF
@@ -725,6 +725,7 @@
       // TypeScript type checking
       useTypeScript &&
         new ForkTsCheckerWebpackPlugin({
+          useTypescriptIncrementalApi: false,
           typescript: resolve.sync('typescript', {
             basedir: paths.appNodeModules,
           }),
EOF
yarn build
# number of watchers stays at 0, and the build is faster

我已经验证了所有监视器都属于运行 fork-ts-checker-webpack-plugin 的节点进程。

预期行为

整个构建过程中 inotify watches 的数量保持为0。

实际行为

inotify watches 的数量增加到5497。

可重现演示

请参阅重现步骤。

可能的解决方案

添加一个选项完全关闭 fork-ts-checker-webpack-plugin,或者禁用 useTypescriptIncrementalApi

useTypescriptIncrementalApi: !process.env["CI"],
sxissh06

sxissh061#

我尝试使用上述的Docker脚本在Jenkins上运行现有的项目,但是出现了问题。同时,watches的数量增长到了12052。可以确认,当useTypescriptIncrementalApi设置为false时,这个数量会变为0。

kpbwa7wx

kpbwa7wx2#

这个问题已经被自动标记为过时,因为它没有任何最近的活动。如果没有发生任何进一步的活动,它将在5天后被关闭。

相关问题