Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared memory descriptors are not closed after PHP program execution is complete. #17245

Open
CoderAImen opened this issue Dec 23, 2024 · 4 comments · May be fixed by #17273
Open

Shared memory descriptors are not closed after PHP program execution is complete. #17245

CoderAImen opened this issue Dec 23, 2024 · 4 comments · May be fixed by #17273

Comments

@CoderAImen
Copy link

Description

Extension SHMOP.

shm_id = shmop_open($r, "c", 0644,1024000); ?>

When the web server is running for a long time, the number of open descriptors reaches 15 million or more. As a result, the web server complains about the lack of resources.

Shared memory descriptors are not closed after PHP program execution is complete.

Apache 2.4.62 PHP 8.4(php8apache2_4.dll) Windows 11.

PHP Version

PHP 8.4

Operating System

Windows 11

@cmb69
Copy link
Member

cmb69 commented Dec 23, 2024

php-src/TSRM/tsrm_win32.c

Lines 751 to 754 in bf5e6c5

if (shm->descriptor->shm_nattch <= 0) {
ret = UnmapViewOfFile(shm->descriptor) ? 0 : -1;
shm->descriptor = NULL;
}

It seems to me that we need to unmap unconditionally, but should close the handle if the refcount drops to zero (the latter might not be necessary).

@CoderAImen
Copy link
Author

php-src/TSRM/tsrm_win32.c

Lines 751 to 754 in bf5e6c5

if (shm->descriptor->shm_nattch <= 0) {
ret = UnmapViewOfFile(shm->descriptor) ? 0 : -1;
shm->descriptor = NULL;
}

It seems to me that we need to unmap unconditionally, but should close the handle if the refcount drops to zero (the latter might not be necessary).

php-src/TSRM/tsrm_win32.c

Lines 686 to 691 in bf5e6c5

shm = shm_get(key, NULL);
if (!shm) {
CloseHandle(shm_handle);
return -1;
}
shm->segment = shm_handle;

At this point the open Handle is lost, since no one closed shm->segment.

@dktapps
Copy link
Contributor

dktapps commented Dec 24, 2024

Is this a problem outside of shmop? It might explain some strange "out of resources" user issues I've seen in my applications over the years. Basically, is OPcache also affected by this?

@cmb69
Copy link
Member

cmb69 commented Dec 24, 2024

OPcache should not be affected, but the underlying emulation of POSIX shared memory primitives is in tsrm_win32.c, and can be used by other clients than ext/shmop (for instance, it is also used by ext/sysvshm).

@CoderAImen CoderAImen linked a pull request Dec 26, 2024 that will close this issue
@devnexen devnexen linked a pull request Dec 26, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants