Skip to content

Commit baaf8fb

Browse files
jhaigh0peterfpeterson
authored andcommitted
Raise open file descriptors limit to avoid problem with pystack (mantidproject#40108)
### Description of work The recent problems with running `pystack` in the error reporter have been traced back to the fact that `pystack` was trying to open more file descriptors than the limit set on most linux systems. A pr into `pystack` has been made to improve their error messages (bloomberg/pystack#260). When this is a problem, you get a lot of this kind of output ``` ERROR(process_core): Cannot open ELF file /home/bya67386/mambaforge/envs/test_htlp_links/lib/python3.11/site-packages/mantid/kernel/../../../.././libMantidJson.so ERROR(process_core): Cannot open ELF file /home/bya67386/mambaforge/envs/test_htlp_links/lib/python3.11/site-packages/mantid/kernel/../../../.././libMantidJson.so ERROR(process_core): Cannot open ELF file /home/bya67386/mambaforge/envs/test_htlp_links/lib/python3.11/site-packages/mantid/kernel/../../../.././libMantidJson.so ERROR(process_core): Cannot open ELF file /home/bya67386/mambaforge/envs/test_htlp_links/lib/python3.11/site-packages/mantid/kernel/../../../.././libMantidJson.so ERROR(process_core): Cannot open ELF file /home/bya67386/mambaforge/envs/test_htlp_links/lib/python3.11/site-packages/mantid/kernel/../../../../libMantidTypes.so ERROR(process_core): Cannot open ELF file /home/bya67386/mambaforge/envs/test_htlp_links/lib/python3.11/site-packages/mantid/kernel/../../../../libMantidTypes.so ERROR(process_core): Cannot open ELF file /home/bya67386/mambaforge/envs/test_htlp_links/lib/python3.11/site-packages/mantid/kernel/../../../../libMantidTypes.so ERROR(process_core): Cannot open ELF file /home/bya67386/mambaforge/envs/test_htlp_links/lib/python3.11/site-packages/mantid/kernel/../../../../libMantidTypes.so ERROR(process_core): Cannot open ELF file /home/bya67386/mambaforge/envs/test_htlp_links/lib/python3.11/site-packages/mantid/kernel/../../../../libMantidPythonInterfaceCore.so ERROR(process_core): Cannot open ELF file /home/bya67386/mambaforge/envs/test_htlp_links/lib/python3.11/site-packages/mantid/kernel/../../../../libMantidPythonInterfaceCore.so ERROR(process_core): Cannot open ELF file /home/bya67386/mambaforge/envs/test_htlp_links/lib/python3.11/site-packages/mantid/kernel/../../../../libMantidPythonInterfaceCore.so ERROR(process_core): Cannot open ELF file /home/bya67386/mambaforge/envs/test_htlp_links/lib/python3.11/site-packages/mantid/kernel/../../../../libMantidPythonInterfaceCore. ``` The issue started after the first new instrument view pr went in (this commit mantidproject@8733e98#diff-4a6d6571d2c59705d8a673667672de2d7dcc3c756c61a3f0195acdefac52fe34). We're not that sure why, but it could be the addition of new libraries such as `pyvista`. This pr raises the limit (equivalent to `ulimit -n <value>`) for the outer mantid process, which may eventually launch the error reporter. ### To test: Package to test is at `mamba install jhaigh0/label/raise_open_files_limit::mantidworkbench` It would be good to test on idaaas where the core dump location is already set up. Run Segfault and check that the pystack output has been captured in the stacktrace field.
1 parent da4a031 commit baaf8fb

File tree

1 file changed

+23
-11
lines changed
  • qt/applications/workbench/workbench/app

1 file changed

+23
-11
lines changed

qt/applications/workbench/workbench/app/start.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import subprocess
1010
import sys
1111

12-
from mantid.kernel.environment import is_linux, is_windows
12+
from mantid.kernel.environment import is_linux
1313
from mantid.kernel import Logger
1414

1515
if is_linux():
@@ -38,17 +38,28 @@ def start_error_reporter(workbench_pid):
3838
)
3939

4040

41-
def setup_core_dump_files():
41+
def _setup_core_dump_files():
4242
"""
4343
This is done so that the error reporter can locate and read any core files produced.
4444
This allows us to recover traces from c++ based crashes.
4545
"""
46-
if is_linux():
47-
try:
48-
resource.setrlimit(resource.RLIMIT_CORE, (resource.RLIM_INFINITY, resource.getrlimit(resource.RLIMIT_CORE)[1]))
49-
except ValueError as e:
50-
log = Logger("Mantid Start")
51-
log.warning(f"Problem when enabling core dumps\n{str(e)}")
46+
try:
47+
resource.setrlimit(resource.RLIMIT_CORE, (resource.RLIM_INFINITY, resource.getrlimit(resource.RLIMIT_CORE)[1]))
48+
except ValueError as e:
49+
log = Logger("Mantid Start")
50+
log.warning(f"Problem when enabling core dumps\n{str(e)}")
51+
52+
53+
def _raise_open_file_descriptor_limit():
54+
"""
55+
Done to avoid the limit being reached when running pystack in the error reporter
56+
"""
57+
try:
58+
nofile_max = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
59+
resource.setrlimit(resource.RLIMIT_NOFILE, (nofile_max, nofile_max))
60+
except ValueError as e:
61+
log = Logger("Mantid Start")
62+
log.warning(f"Problem when raising limit for number of open file descriptors\n{str(e)}")
5263

5364

5465
def start(options: argparse.ArgumentParser):
@@ -74,9 +85,10 @@ def start(options: argparse.ArgumentParser):
7485
if options.quit:
7586
launch_command += " --quit"
7687

77-
if not is_windows():
78-
# preexec_fn is not supported on Windows
79-
workbench_process = subprocess.Popen(launch_command, shell=True, preexec_fn=setup_core_dump_files)
88+
if is_linux():
89+
# currently, reading coredump files for error reports is only supported on linux
90+
_raise_open_file_descriptor_limit()
91+
workbench_process = subprocess.Popen(launch_command, shell=True, preexec_fn=_setup_core_dump_files)
8092
else:
8193
workbench_process = subprocess.Popen(launch_command, shell=True)
8294

0 commit comments

Comments
 (0)