stan-dev / pystan

PyStan, a Python interface to Stan, a platform for statistical modeling. Documentation: https://pystan.readthedocs.io
ISC License
337 stars 58 forks source link

File descriptor leak #377

Closed AlexHls closed 1 year ago

AlexHls commented 1 year ago

Describe the bug

Sampling a model leaks file descriptors, which becomes a problem when running many fits in sequence using the same process (e.g. during bootstrap resampling). Increasing the number of possible open files is a possible temporary fix, but does not work for huge number of resampling sequences. In my case, I need to run ~510^6 fits, which inevitably leads to and OSError [Errno 24]. It seems to originate from some bad file descriptors left behind by the `/tmp/httpstan_.sockfiles and some sockets (i.e. when trying to manually close the file descriptors,os.fstat` returns a BadFileDescriptor error). I've attached a MWE illustarting the increase in the number of used file descriptors. This might be an upstream problem, but I could not verify this.

Describe your system

riddell-stan commented 1 year ago

Thanks for the investigation.

What version of httpstan are you using? This should have been fixed in https://github.com/stan-dev/httpstan/pull/614

AlexHls commented 1 year ago

Apparently my httpstan version did not update when updating pystan. Updating manually to the newest version of httpstan seems to fix the issue. Thanks for the hint.