bitwiseworks / libcx

kLIBC Extension Library
GNU Lesser General Public License v2.1
11 stars 1 forks source link

Consider enhancing mmap() error handling. #38

Closed StevenLevine closed 7 years ago

StevenLevine commented 7 years ago

Currently mmap.c:484 arc = DosDupHandle(fildes, &fh->fd);

will fail if DosDupHandle fails with ERROR_TOO_MANY_OPEN_FILES. This can be avoided by invoking DosSetRelMaxFH to increase the number of available handles and retrying the request.

FWIW, there is a potential conflict with kLIBC. It is possible that the duplicated handles will conflict with one of kLIBC's faked socket handles. This will not be an issue as long as the handle created by mmap() is never passed to kLIBC.

dmik commented 7 years ago

@StevenLevine thanks for creating a ticket for that! Can you please remind me which use case exactly brought this problem for you? So that I could test it locally. I remember you told me once but I can't find it in logs.

StevenLevine commented 7 years ago

Any large repo with sufficient update activity should be a good testcase

Try: git://github.com/php/php-src.git

I tend to use git:// rather than https:// because git:// seems to be faster.

The error you should see is fatal: mmap failed: Too many open files

The initial git clone should have no issues. However a git pull or git fsck will eventually report out of handles errors in mmap.

dmik commented 7 years ago

Right. I recalled it now, thanks. BTW, as this shows up under heavy load, it has some similarities with #30 in this regard. JFYI.

dmik commented 7 years ago

Unfortunately, I cannot reproduce the problem myself but I implemented the suggested fix (mmap file handles are never passed to LIBC so it should be safe). Please check in your environment.