<div dir="ltr"><div dir="ltr"><div dir="ltr">Hello!<div><br></div><div>As far as I understand it, `ngx_create_pidfile` is a function that works independently. There is no action to close the pid file externally, so we need to close the pid file when the writing it failed. There are also reports here <a href="https://github.com/nginx/nginx/pull/52">https://github.com/nginx/nginx/pull/52</a>.</div><div><br></div><div># HG changeset patch<br># User Jinhua Tan <<a href="mailto:312841925@qq.com">312841925@qq.com</a>><br># Date 1590068494 -28800<br>#      Thu May 21 21:41:34 2020 +0800<br># Node ID 6084ea4d9a4d2ae32f3fc4e2e3b9032ab0b71e30<br># Parent  3242f98298975e556a7e87130611ce84799fe935<br>Core: close pid file while writing it failed.<br><br>diff -r 3242f9829897 -r 6084ea4d9a4d src/core/ngx_cycle.c<br>--- a/src/core/ngx_cycle.c      Wed May 20 12:24:05 2020 +0800<br>+++ b/src/core/ngx_cycle.c      Thu May 21 21:41:34 2020 +0800<br>@@ -1036,6 +1036,12 @@<br>         len = ngx_snprintf(pid, NGX_INT64_LEN + 2, "%P%N", ngx_pid) - pid;<br><br>         if (ngx_write_file(&file, pid, len, 0) == NGX_ERROR) {<br>+<br>+            if (ngx_close_file(file.fd) == NGX_FILE_ERROR) {<br>+                ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,<br>+                              ngx_close_file_n " \"%s\" failed", file.name.data);<br>+            }<br>+<br>             return NGX_ERROR;<br>         }<br>     }<br></div><div><br></div><div>Thank you!</div></div></div></div>