[PATCH 1 of 4] Fix socket leak with AIO
Maxim Dounin
mdounin at mdounin.ru
Mon Oct 11 17:03:20 MSD 2010
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1286631445 -14400
# Node ID 38a938ce08300bb57d0f6c885b1d8c35d602419d
# Parent 94b30aa5d8497cc409579f3253dfa3522c55a28b
Fix socket leak with AIO.
When output buffer size was less than file size we are going to send second
aio post happened if non-first aio operation on the file in question was not
able to complete immediately.
Additionally, on Linux aio event's ready flag wasn't reset after submitting
io request, and as a result there were no "[alert] ... second aio post"
messages.
diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c
--- a/src/core/ngx_output_chain.c
+++ b/src/core/ngx_output_chain.c
@@ -74,18 +74,18 @@ ngx_output_chain(ngx_output_chain_ctx_t
}
}
-#if (NGX_HAVE_FILE_AIO)
- if (ctx->aio) {
- return NGX_AGAIN;
- }
-#endif
-
out = NULL;
last_out = &out;
last = NGX_NONE;
for ( ;; ) {
+#if (NGX_HAVE_FILE_AIO)
+ if (ctx->aio) {
+ return NGX_AGAIN;
+ }
+#endif
+
while (ctx->in) {
/*
diff --git a/src/http/ngx_http_copy_filter_module.c b/src/http/ngx_http_copy_filter_module.c
--- a/src/http/ngx_http_copy_filter_module.c
+++ b/src/http/ngx_http_copy_filter_module.c
@@ -211,6 +211,8 @@ ngx_http_copy_aio_handler(ngx_output_cha
r->main->blocked++;
r->aio = 1;
+
+ ctx->aio = 1;
}
diff --git a/src/os/unix/ngx_linux_aio_read.c b/src/os/unix/ngx_linux_aio_read.c
--- a/src/os/unix/ngx_linux_aio_read.c
+++ b/src/os/unix/ngx_linux_aio_read.c
@@ -95,6 +95,10 @@ ngx_file_aio_read(ngx_file_t *file, u_ch
n = io_submit(ngx_aio_ctx, 1, piocb);
if (n == 1) {
+ ev->active = 1;
+ ev->ready = 0;
+ ev->complete = 0;
+
return NGX_AGAIN;
}
More information about the nginx-devel
mailing list