Occasional ENOSPC error on deployments

We get this error from time to time, it’s not a major issue as we’re able to clear cache and redeploy which then successfully deploys our site but just wanted to flag it.

11:13:40 AM: error ENOSPC: System limit for number of file watchers reached, watch '/opt/build/repo/gatsby-config.js'
11:13:40 AM: UNHANDLED EXCEPTION ENOSPC: System limit for number of file watchers reached, watch '/opt/build/repo/gatsby-config.js'
11:13:40 AM: See our docs page for more info on this error: https://gatsby.dev/issue-how-to
11:13:40 AM: 
11:13:40 AM:   Error: ENOSPC: System limit for number of file watchers reached, watch '/opt/b  uild/repo/gatsby-config.js'
11:13:40 AM:   
11:13:40 AM:   - watchers.js:165 FSWatcher.start
11:13:40 AM:     internal/fs/watchers.js:165:26
11:13:40 AM:   
11:13:40 AM:   - nodefs-handler.js:38 createFsWatchInstance
11:13:40 AM:     [repo]/[chokidar]/lib/nodefs-handler.js:38:15
11:13:40 AM:   
11:13:40 AM:   - nodefs-handler.js:81 setFsWatchListener
11:13:40 AM:     [repo]/[chokidar]/lib/nodefs-handler.js:81:15
11:13:40 AM:   
11:13:40 AM:   - nodefs-handler.js:233 FSWatcher.NodeFsHandler._watchWithNodeFs
11:13:40 AM:     [repo]/[chokidar]/lib/nodefs-handler.js:233:14
11:13:40 AM:   
11:13:40 AM:   - nodefs-handler.js:262 FSWatcher.NodeFsHandler._handleFile
11:13:40 AM:     [repo]/[chokidar]/lib/nodefs-handler.js:262:21
11:13:40 AM:   
11:13:40 AM:   - nodefs-handler.js:495 FSWatcher.<anonymous>
11:13:40 AM:     [repo]/[chokidar]/lib/nodefs-handler.js:495:21
11:13:40 AM:   
1 Like

This is a known limitation of the build image. There is a public repo for this but the issue is internal only:

You mentioned clearing the build cache resolves this. If so, this could be an issue where any entire directory tree is being watched which should not be. For example, if Gatsby is watching all of ./node_modules/ this is probably not what is expected and could be contributing to this issue. This would be becaue ./node_modules/ grows over time and hits the limit (and why clearing the cache resolves it).

On the other hand, the inotify watchers limit is currently only 8192 in our build image. As this is a kernel level shared resource, other builds can compete for that resource so that could be another reason it fails sometimes and not others. Sometimes there is another build also using many inotify watchers and when it is retried there isn’t one.

All this being said, making certain that Gatsby is only watching the directories you actually care about would be one way to reduce the likelihood of this occurring.

If we increase the inotify watchers limit we will also update this topic here in the community to let you know. (Note, we are carefully considering this possible change because it has potential downsides - specifically increasing the watcher limit allocates/consumes system memory which isn’t recoverable unless the setting is reduced and the system is rebooted.)

As always, any/all questions are welcome.

1 Like