[nginx] Worked around EINVAL from shutdown() on NetBSD.
Maxim Dounin
mdounin at mdounin.ru
Sat Jul 19 02:59:15 UTC 2025
details: http://freenginx.org/hg/nginx/rev/e0792bb674b0
branches:
changeset: 9396:e0792bb674b0
user: Maxim Dounin <mdounin at mdounin.ru>
date: Sat Jul 19 05:57:53 2025 +0300
description:
Worked around EINVAL from shutdown() on NetBSD.
If a connection was reset by the client, shutdown() on NetBSD returns
EINVAL, leading to test failures, as seen in the ssl_conf_command.t
test.
Fix is to ignore EINVAL from shutdown() on NetBSD, similarly to how we
do with EINVAL from setsockopt() on Solaris.
diffstat:
src/core/ngx_connection.c | 2 --
src/http/ngx_http_request.c | 4 ++++
src/http/v2/ngx_http_v2.c | 4 ++++
src/mail/ngx_mail_handler.c | 4 ++++
4 files changed, 12 insertions(+), 2 deletions(-)
diffs (57 lines):
diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -1619,11 +1619,9 @@ ngx_connection_error(ngx_connection_t *c
return 0;
}
-#if (NGX_SOLARIS)
if (err == NGX_EINVAL && c->log_error == NGX_ERROR_IGNORE_EINVAL) {
return 0;
}
-#endif
if (err == NGX_EMSGSIZE && c->log_error == NGX_ERROR_IGNORE_EMSGSIZE) {
return 0;
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -3579,6 +3579,10 @@ ngx_http_set_lingering_close(ngx_connect
}
if (ngx_shutdown_socket(c->fd, NGX_WRITE_SHUTDOWN) == -1) {
+#if (defined __NetBSD__)
+ /* NetBSD returns EINVAL if the connection was reset */
+ c->log_error = NGX_ERROR_IGNORE_EINVAL;
+#endif
ngx_connection_error(c, ngx_socket_errno,
ngx_shutdown_socket_n " failed");
ngx_http_close_request(r, 0);
diff --git a/src/http/v2/ngx_http_v2.c b/src/http/v2/ngx_http_v2.c
--- a/src/http/v2/ngx_http_v2.c
+++ b/src/http/v2/ngx_http_v2.c
@@ -805,6 +805,10 @@ ngx_http_v2_lingering_close(ngx_connecti
}
if (ngx_shutdown_socket(c->fd, NGX_WRITE_SHUTDOWN) == -1) {
+#if (defined __NetBSD__)
+ /* NetBSD returns EINVAL if the connection was reset */
+ c->log_error = NGX_ERROR_IGNORE_EINVAL;
+#endif
ngx_connection_error(c, ngx_socket_errno,
ngx_shutdown_socket_n " failed");
ngx_http_close_connection(c);
diff --git a/src/mail/ngx_mail_handler.c b/src/mail/ngx_mail_handler.c
--- a/src/mail/ngx_mail_handler.c
+++ b/src/mail/ngx_mail_handler.c
@@ -1330,6 +1330,10 @@ ngx_mail_lingering_close(ngx_connection_
}
if (ngx_shutdown_socket(c->fd, NGX_WRITE_SHUTDOWN) == -1) {
+#if (defined __NetBSD__)
+ /* NetBSD returns EINVAL if the connection was reset */
+ c->log_error = NGX_ERROR_IGNORE_EINVAL;
+#endif
ngx_connection_error(c, ngx_socket_errno,
ngx_shutdown_socket_n " failed");
ngx_mail_close_connection(c);
More information about the nginx-devel
mailing list