Why am I hitting file number limit prematurely?
Resource limits can be set differently for different users and different processes. Your ulimit
shows specific limits for a specific user but systemd
has its own default limits. You need to update your systemd
unit file for your program to set file limits LimitNOFILE=1048576
See the documentation for details