【解決】Error: ENOSPC: no space left on device, watch


發現問題:

啟動 node 項目ReactNative時候出現報錯Error: ENOSPC: no space left on device, watch

[root@iz2zeihk6kfcls5kwmqzj1z JFReactNativeProject]# npm start

> wk_rn@0.0.1 start /app/jenkins_workspace/workspace/JFReactNativeProject
> react-native start

┌──────────────────────────────────────────────────────────────────────────────┐
│                                                                              │
│  Running Metro Bundler on port 8081.                                         │
│                                                                              │
│  Keep Metro running while developing on any JS projects. Feel free to        │
│  close this tab and run your own Metro instance if you prefer.               │
│                                                                              │
│  https://github.com/facebook/react-native                                    │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

Looking for JS files in
   /app/jenkins_workspace/workspace/JFReactNativeProject

Loading dependency graph...fs.js:1413
    throw error;
    ^

Error: ENOSPC: no space left on device, watch '/app/jenkins_workspace/workspace/JFReactNativeProject/node_modules/.staging/react-native-ddd311e5/ReactAndroid/src/androidTest/java/com/facebook/react/testing/idledetection'
    at FSWatcher.start (fs.js:1407:26)
    at Object.fs.watch (fs.js:1444:11)
    at NodeWatcher.watchdir (/app/jenkins_workspace/workspace/JFReactNativeProject/node_modules/_sane@4.1.0@sane/src/node_watcher.js:159:22)
    at Walker.<anonymous> (/app/jenkins_workspace/workspace/JFReactNativeProject/node_modules/_sane@4.1.0@sane/src/common.js:109:31)
    at Walker.emit (events.js:182:13)
    at /app/jenkins_workspace/workspace/JFReactNativeProject/node_modules/_walker@1.0.7@walker/lib/walker.js:69:16
    at go$readdir$cb (/app/jenkins_workspace/workspace/JFReactNativeProject/node_modules/_graceful-fs@4.2.2@graceful-fs/graceful-fs.js:187:14)
    at FSReqWrap.oncomplete (fs.js:169:20)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! wk_rn@0.0.1 start: `react-native start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the wk_rn@0.0.1 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-09-25T06_57_58_754Z-debug.log

解決辦法:

ENOSPC的含義是 Error No more hard-disk space available(沒有更多的磁盤空間可以使用)

首先使用df -hT發現磁盤空間還有很多

然后從報錯日志中發現FSWatcherObject.fs.watch字段,然后查看系統允許用戶監聽文件數相關內容

#表示同一用戶同時可以添加的watch數目(watch一般是針對目錄,決定了同時同一用戶可以監控的目錄數量)
[root@iz2zeihk6kfcls5kwmqzj1z JFReactNativeProject]# cat /proc/sys/fs/inotify/max_user_watches
8192
[root@iz2zeihk6kfcls5kwmqzj1z JFReactNativeProject]# echo 100000 > /proc/sys/fs/inotify/max_user_watches
[root@iz2zeihk6kfcls5kwmqzj1z JFReactNativeProject]# cat /proc/sys/fs/inotify/max_user_watches
100000

永久生效方法如下:(建議采用此方法)

vim /etc/sysctl.conf
fs.inotify.max_user_watches = 100000(后面值根據實際情況可自行調整)
添加並運行/sbin/sysctl -p即可 

啟動驗證:

再次啟動,正常

[root@iz2zeihk6kfcls5kwmqzj1z JFReactNativeProject]# npm start

> wk_rn@0.0.1 start /app/jenkins_workspace/workspace/JFReactNativeProject
> react-native start

┌──────────────────────────────────────────────────────────────────────────────┐
│                                                                              │
│  Running Metro Bundler on port 8081.                                         │
│                                                                              │
│  Keep Metro running while developing on any JS projects. Feel free to        │
│  close this tab and run your own Metro instance if you prefer.               │
│                                                                              │
│  https://github.com/facebook/react-native                                    │
│                                                                              │
└──────────────────────────────────────────────────────────────────────────────┘

Looking for JS files in
   /app/jenkins_workspace/workspace/JFReactNativeProject

Loading dependency graph, done.

知識點:

inotify 的默認內核參數

  • /proc/sys/fs/inotify/max_queued_events 默認值: 16384 該文件中的值為調用inotify_init時分配給inotify instance中可排隊的event的數目的最大值,超出這個值得事件被丟棄,但會觸發IN_Q_OVERFLOW事件
  • /proc/sys/fs/inotify/max_user_instances 默認值: 128 指定了每一個real user ID可創建的inotify instatnces的數量上限
  • /proc/sys/fs/inotify/max_user_watches 默認值: 8192 指定了每個inotify instance相關聯的watches的上限

注意: max_queued_events 是 Inotify 管理的隊列的最大長度,文件系統變化越頻繁,這個值就應該越大
如果你在日志中看到Event Queue Overflow,說明 max_queued_events 太小需要調整參數后再次使用.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM