[go: up one dir, main page]

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

error_log on Windows can hold the file write lock #8923

Closed
neil-pearce opened this issue Jul 5, 2022 · 1 comment
Closed

error_log on Windows can hold the file write lock #8923

neil-pearce opened this issue Jul 5, 2022 · 1 comment

Comments

@neil-pearce
Copy link

Description

The problem can only be seen on a very busy Windows box. If error_log is called then the lock is not immediately released by the file close but at a time that "depends upon available system resources". This is a 'feature' of the Windows function LockFileEx. The problem has already been addressed in the routine ps_files_close (in the file mod_files.c):

static void ps_files_close(ps_files *data)
{
	if (data->fd != -1) {
#ifdef PHP_WIN32
		/* On Win32 locked files that are closed without being explicitly unlocked
		   will be unlocked only when "system resources become available". */
		flock(data->fd, LOCK_UN);
#endif
		close(data->fd);
		data->fd = -1;
	}
}

The same logic should be implemented in the routine php_log_err_with_severity (in main.c).

PHP Version

All versions

Operating System

Windows

@cmb69
Copy link
Member
cmb69 commented Jul 5, 2022

Good bug report. Thank you!

@cmb69 cmb69 self-assigned this Jul 5, 2022
cmb69 added a commit to cmb69/php-src that referenced this issue Jul 5, 2022
On Windows, closing a file which is locked may not immediately remove
the lock.  The `LockFileEx()` documentation states:

| Therefore, it is recommended that your process explicitly unlock all
| files it has locked when it terminates.

We comply, and also use the macro `LOCK_EX` instead of the magic number
`2`.
@cmb69 cmb69 linked a pull request Jul 5, 2022 that will close this issue
cmb69 added a commit that referenced this issue Jul 12, 2022
* PHP-8.0:
  Fix GH-8923: error_log on Windows can hold the file write lock
@cmb69 cmb69 closed this as completed in 77e954a Jul 12, 2022
cmb69 added a commit that referenced this issue Jul 12, 2022
* PHP-8.1:
  Fix GH-8923: error_log on Windows can hold the file write lock
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.

2 participants