title: How can I raise the limit for open files in Ubuntu 20.04 on WSL2?
body: <p>My setup looks as follows: Windows 10, Release 1909 (Build 18363.1082), using WSL2 with an Ubuntu 20.04 environment. Everything works nicely most of the time, but there are some issues I cannot manage to solve.</p>
  <p>During development using <code>parcel</code> (React bundler), I run into the problem that the bundler apparently opens <strong>lots</strong> of files at the same time, and at a certain point, I run into the following problem:</p>
  <pre><code>EMFILE: too many open files, open '/home/myusername/Projects/some-project-path/node_modules/@material-ui/icons/esm/RoundedCornerRounded.js'
  </code></pre>
  <p>As <code>parcel</code> seemingly does not easily support using something like <code>graceful-fs</code>, I have tried to increase the limit for open files inside the Ubuntu environment. What I have tried so far:</p>
  <ul>
  <li>A simple <code>ulimit -n 4096</code> (which is the highest possible by default), but it's apparently (by far?) not enough</li>
  <li>I tried increasing <code>fs.files-max</code> to something really high in <code>/etc/sysctl.conf</code>, but it doesn't seem to have an effect (neither after <code>sysctl -p</code> nor after a restart of <code>wsl</code>)</li>
  <li>I also tried increasing <code>fs.inotify.max_user_watches</code>, but that did not seem to have an effect either</li>
  <li>Also setting soft and hard limits in <code>/etc/security/limits.conf</code> did not seem to have an effect</li>
  <li>I also found information that changing <code>DefaultLimitNOFILE</code> in <code>/etc/systemd/system.conf</code> can have an effect (so I did that as well)</li>
  </ul>
  <p>Has anybody manage to solve a similar system on Ubuntu 20.04 on WSL2? This left me pretty stumped, and it prevents me from using <code>parcel</code> inside this environment. That's a real pity, as really everything else is working really fine.</p>
  <hr />
  <h2>UPDATE</h2>
  <p>So I have found out that my changes in various places (probably the one in <code>/etc/security/limits.conf</code>) has had some kind of effect. Just not when logging in directly. This illustrates this:</p>
  <pre><code>donmartin@SOMEMACHINE:~$ ulimit -Hn
  4096
  donmartin@SOMEMACHINE:~$ su donmartin
  Password:
  donmartin@SOMEMACHINE:~$ ulimit -Hn
  65536
  donmartin@SOMEMACHINE:~$
  </code></pre>
  <p>Which means: If I <code>su</code> to my own user, the <code>ulimit</code> has indeed been raised. But if I log in just as normal using Windows Terminal, this limit is <strong>not</strong> in effect. Even more puzzled now - BUT - I have a workaround for my problem. Having set my values to <code>65536</code>, the <code>parcel</code> build now works, running as my own user. Go figure! I still don't quite know which setting was changing the behaviour now - perhaps somebody has more thorough information on how this works and/or how I can make this also the default without having to do a <code>su</code> to get the updated limits.</p>