From jan.prachar at gmail.com Wed Jan 2 19:17:46 2019
From: jan.prachar at gmail.com (Jan =?UTF-8?Q?Pracha=C5=99?=)
Date: Wed, 02 Jan 2019 20:17:46 +0100
Subject: SSL_shutdown() return value <0
In-Reply-To: <20181211133348.GW99070@mdounin.ru>
References: <7eb37d13ecfeeb33b090ee64152e2b04a2e8806c.camel@gmail.com>
<20181211133348.GW99070@mdounin.ru>
Message-ID: <31c9fd6621f695a7e27ef9daf9b03cff8a581010.camel@gmail.com>
Hello! Thanks for the detailed explanation of ignoring
SSL_ERROR_WANT_READ and SSL_ERROR_WANT_WRITE in ngx_ssl_shutdown.
On Tue, 2018-12-11 at 16:33 +0300, Maxim Dounin wrote:
> Hello!
>
> On Mon, Dec 10, 2018 at 09:46:28PM +0100, Jan Pracha? wrote:
> > I have also tried to change the condition to just n < 0, and came
> > to
> > antoher issue. If client closes connection prematurely, there is
> > usually SSL_write, that has failed with error WANT_WRITE. If then
> > the
> > SSL_shutdown is called repeatedly, it causes OpenSSL error (SSL:
> > error:1409F07F:SSL routines:ssl3_write_pending:bad write retry),
> > because pending SSL_write should have been called first.
>
> In many places we try to avoid doing actual SSL shutdown if we
> know there was an error and/or we know the connection was already
> closed, by using c->ssl->no_send_shutdown flag. Existing cases
> might not be enough though.
I have given some time to debug the issue and I have found that in this
case nginx closes the connection inside read event handler
ngx_http_test_reading(). As you adviced, I added
+ #if (NGX_HTTP_SSL)
+ if (c->ssl) {
+ c->ssl->no_send_shutdown = 1;
+ }
+ #endif
+
ngx_http_finalize_request(r, NGX_HTTP_CLIENT_CLOSED_REQUEST);
}
just before the last line in the function, and then all errors
SSL: error:1409F07F:SSL routines:ssl3_write_pending:bad write retry
dissapear.
-- Jan Pracha?
From fdintino at theatlantic.com Thu Jan 3 05:21:15 2019
From: fdintino at theatlantic.com (Frankie Dintino)
Date: Thu, 3 Jan 2019 00:21:15 -0500
Subject: rate limit request body read from a body filter? (nginx-upload-module)
Message-ID: <7C63024C-E4EE-419E-AFCC-0E29D839C9E7@theatlantic.com>
Hi,
I'm currently trying to rewrite https://github.com/fdintino/nginx-upload-module/ as a request body filter, in order to simplify the code and future-proof it (as it's currently written, there's a lot of copypasta from ngx_http_request_body.c that is very fragile and probably already incompatible with new features and third party modules).
I'm nearly done this work, but I've hit a stumbling block trying to port the upload rate limiting feature. The current implementation completely overrides the request handler, so rate-limiting the request body is pretty trivial: if you need to delay the next buffer read, to stay within the rate limit, you can set c->read->delayed = 1, call ngx_add_timer(c->read, delay), and return NGX_AGAIN.
When I try this from the request body filter, I'm able to delay the very next read event, but afterwards when control is returned to the outer request handler, the rate that read buffers get consumed is no longer within my control (also, returning NGX_AGAIN from the body handler to the http2 request handler doesn't work at all?it raises a 500?but that's another issue).
So it seems to me that?if I want to keep the upload rate limiting feature?I'm going to have to do it somewhere else, maybe in a custom read event handler. Is there another option I'm not thinking of? And if I have to do it in a custom read_event_handler, does anyone have pointers for how I can do this in the least obtrusive way?
Thanks!
Frankie Dintino
The Atlantic
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From msellers at ranchmed.com Thu Jan 3 16:46:30 2019
From: msellers at ranchmed.com (Mark Sellers)
Date: Thu, 3 Jan 2019 08:46:30 -0800
Subject: Module executed w/o directive in config
Message-ID: <193650F6-8669-4393-9894-B64F71ECB8A8@ranchmed.com>
I am building a simple module that does a uri rewrite (not using the rewrite module). The module directive is fastimg_rewrite with no parameters.
I build the code, including the module.
When attempt to access any url, I get an error in the log:
*1 rewrite or internal redirection cycle while internally redirecting to "/images/bar/index.html?
Funny thing is, I have not added the directive to my config file yet!
Q1: Directive not in config - why is my module executing?
Q2: What does this error message indicate? I do want to redirect to ?/images/bar/index.html?!!
Here is the config file:
server {
listen 192.168.1.101:80;
server_name dev.static.ranchmed.com ;
root /var/www/html/static.ranchmed.com ;
charset UTF-8;
location / {
}
location /images/ {
# fastimg_rewrite;
# try_files $uri @fastimg_fcgi;
}
location @fastimg_fcgi {
include fastcgi_params;
fastcgi_pass 127.0.0.1:3000;
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From mdounin at mdounin.ru Fri Jan 4 05:38:08 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Fri, 4 Jan 2019 08:38:08 +0300
Subject: Module executed w/o directive in config
In-Reply-To: <193650F6-8669-4393-9894-B64F71ECB8A8@ranchmed.com>
References: <193650F6-8669-4393-9894-B64F71ECB8A8@ranchmed.com>
Message-ID: <20190104053808.GK99070@mdounin.ru>
Hello!
On Thu, Jan 03, 2019 at 08:46:30AM -0800, Mark Sellers wrote:
> I am building a simple module that does a uri rewrite (not using
> the rewrite module). The module directive is fastimg_rewrite
> with no parameters.
>
> I build the code, including the module.
>
> When attempt to access any url, I get an error in the log:
>
> *1 rewrite or internal redirection cycle while internally
> redirecting to "/images/bar/index.html?
>
> Funny thing is, I have not added the directive to my config file
> yet!
>
> Q1: Directive not in config - why is my module executing?
It is the module which decides what to do, and whether to do
anything without any directives in the configuration, or not.
That is, check your code.
> Q2: What does this error message indicate? I do want to redirect to ?/images/bar/index.html?!!
The message indicates that there were too many redirects, and
nginx decided to stop it. Most likely, your code redirects all
requests, including already redirected ones, and this is what
causes the problem.
--
Maxim Dounin
http://mdounin.ru/
From vadimjunk at gmail.com Sun Jan 6 21:40:28 2019
From: vadimjunk at gmail.com (Vadim Fedorenko)
Date: Mon, 7 Jan 2019 00:40:28 +0300
Subject: remove unneeded io_getevents syscall.
Message-ID:
# HG changeset patch
# User Vadim Fedorenko
# Date 1546810494 0
# Sun Jan 06 21:34:54 2019 +0000
# Node ID 3e538f6b8267d36f97b7dd67714c6ba0fba5e5bc
# Parent 6d15e452fa2eaf19408e24a0d0fcc3a31344a289
remove unneeded io_getevents syscall.
This work is based on cloudflare's work on optimization Linux AIO.
https://blog.cloudflare.com/io_submit-the-epoll-alternative-youve-never-heard-about/
The code is compilation of libaio library, it eliminates unnecessary
context-switch on getting new AIO events, doing all possible work in
userspace.
diff -r 6d15e452fa2e -r 3e538f6b8267 src/event/modules/ngx_epoll_module.c
--- a/src/event/modules/ngx_epoll_module.c Tue Dec 25 17:53:03 2018 +0300
+++ b/src/event/modules/ngx_epoll_module.c Sun Jan 06 21:34:54 2019 +0000
@@ -100,6 +100,35 @@
ngx_uint_t aio_requests;
} ngx_epoll_conf_t;
+#if (NGX_HAVE_FILE_AIO)
+
+/* Stolen from kernel arch/x86_64.h */
+#ifdef __x86_64__
+#define read_barrier() __asm__ __volatile__("lfence" ::: "memory")
+#else
+#ifdef __i386__
+#define read_barrier() __asm__ __volatile__("" : : : "memory")
+#else
+#define read_barrier() __sync_synchronize()
+#endif
+#endif
+
+/* Stolen from kernel fs/aio.c */
+#define AIO_RING_MAGIC 0xa10a10a1
+struct aio_ring {
+ unsigned id; /* kernel internal index number */
+ unsigned nr; /* number of io_events */
+ unsigned head;
+ unsigned tail;
+ unsigned magic;
+ unsigned compat_features;
+ unsigned incompat_features;
+ unsigned header_length; /* size of aio_ring */
+ struct io_event events[0];
+};
+
+#endif
+
static ngx_int_t ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer);
#if (NGX_HAVE_EVENTFD)
@@ -241,6 +270,39 @@
io_getevents(aio_context_t ctx, long min_nr, long nr, struct io_event *events,
struct timespec *tmo)
{
+ /* Code based on cloudflare-blog */
+ ngx_int_t i = 0;
+
+ struct aio_ring *ring = (struct aio_ring *)ctx;
+ if (ring == NULL || ring->magic != AIO_RING_MAGIC) {
+ goto do_syscall;
+ }
+
+ while (i < nr) {
+ unsigned head = ring->head;
+ if (head == ring->tail) {
+ /* There are no more completions */
+ break;
+ } else {
+ /* There is another completion to reap */
+ events[i] = ring->events[head];
+ read_barrier();
+ ring->head = (head + 1) % ring->nr;
+ i++;
+ }
+ }
+
+ if (i == 0 && tmo != NULL && tmo->tv_sec == 0 &&
+ tmo->tv_nsec == 0) {
+ /* Requested non blocking operation. */
+ return 0;
+ }
+
+ if (i && i >= min_nr) {
+ return i;
+ }
+
+do_syscall:
return syscall(SYS_io_getevents, ctx, min_nr, nr, events, tmo);
}
From mdounin at mdounin.ru Mon Jan 7 04:24:48 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Mon, 7 Jan 2019 07:24:48 +0300
Subject: remove unneeded io_getevents syscall.
In-Reply-To:
References:
Message-ID: <20190107042448.GO99070@mdounin.ru>
Hello!
On Mon, Jan 07, 2019 at 12:40:28AM +0300, Vadim Fedorenko wrote:
> # HG changeset patch
> # User Vadim Fedorenko
> # Date 1546810494 0
> # Sun Jan 06 21:34:54 2019 +0000
> # Node ID 3e538f6b8267d36f97b7dd67714c6ba0fba5e5bc
> # Parent 6d15e452fa2eaf19408e24a0d0fcc3a31344a289
> remove unneeded io_getevents syscall.
>
> This work is based on cloudflare's work on optimization Linux AIO.
> https://blog.cloudflare.com/io_submit-the-epoll-alternative-youve-never-heard-about/
> The code is compilation of libaio library, it eliminates unnecessary
> context-switch on getting new AIO events, doing all possible work in
> userspace.
>
> diff -r 6d15e452fa2e -r 3e538f6b8267 src/event/modules/ngx_epoll_module.c
> --- a/src/event/modules/ngx_epoll_module.c Tue Dec 25 17:53:03 2018 +0300
> +++ b/src/event/modules/ngx_epoll_module.c Sun Jan 06 21:34:54 2019 +0000
> @@ -100,6 +100,35 @@
> ngx_uint_t aio_requests;
> } ngx_epoll_conf_t;
>
> +#if (NGX_HAVE_FILE_AIO)
> +
> +/* Stolen from kernel arch/x86_64.h */
> +#ifdef __x86_64__
> +#define read_barrier() __asm__ __volatile__("lfence" ::: "memory")
> +#else
> +#ifdef __i386__
> +#define read_barrier() __asm__ __volatile__("" : : : "memory")
> +#else
> +#define read_barrier() __sync_synchronize()
> +#endif
> +#endif
> +
> +/* Stolen from kernel fs/aio.c */
> +#define AIO_RING_MAGIC 0xa10a10a1
> +struct aio_ring {
> + unsigned id; /* kernel internal index number */
> + unsigned nr; /* number of io_events */
> + unsigned head;
> + unsigned tail;
> + unsigned magic;
> + unsigned compat_features;
> + unsigned incompat_features;
> + unsigned header_length; /* size of aio_ring */
> + struct io_event events[0];
> +};
> +
> +#endif
> +
>
> static ngx_int_t ngx_epoll_init(ngx_cycle_t *cycle, ngx_msec_t timer);
> #if (NGX_HAVE_EVENTFD)
> @@ -241,6 +270,39 @@
> io_getevents(aio_context_t ctx, long min_nr, long nr, struct io_event *events,
> struct timespec *tmo)
> {
> + /* Code based on cloudflare-blog */
> + ngx_int_t i = 0;
> +
> + struct aio_ring *ring = (struct aio_ring *)ctx;
> + if (ring == NULL || ring->magic != AIO_RING_MAGIC) {
> + goto do_syscall;
> + }
> +
> + while (i < nr) {
> + unsigned head = ring->head;
> + if (head == ring->tail) {
> + /* There are no more completions */
> + break;
> + } else {
> + /* There is another completion to reap */
> + events[i] = ring->events[head];
> + read_barrier();
> + ring->head = (head + 1) % ring->nr;
> + i++;
> + }
> + }
> +
> + if (i == 0 && tmo != NULL && tmo->tv_sec == 0 &&
> + tmo->tv_nsec == 0) {
> + /* Requested non blocking operation. */
> + return 0;
> + }
> +
> + if (i && i >= min_nr) {
> + return i;
> + }
> +
> +do_syscall:
> return syscall(SYS_io_getevents, ctx, min_nr, nr, events, tmo);
> }
Thank you for the patch.
This looks like a hack which relies on implementation details of
the kernel code. Even if the hack is indeed correct for the
current kernel code (I actually doubt it is, since it uses
unlocked accesses to the structure which seems to be locked in the
kernel), I do not think we want such code in nginx.
--
Maxim Dounin
http://mdounin.ru/
From sepherosa at gmail.com Tue Jan 8 03:37:03 2019
From: sepherosa at gmail.com (Sepherosa Ziehau)
Date: Tue, 8 Jan 2019 11:37:03 +0800
Subject: aio/unix: Use signal.sival which is standard
Message-ID:
sigval.sigval is for FreeBSD 6 compability, while FreeBSD 6 was EOL
for quite a while.
Patch:
https://leaf.dragonflybsd.org/~sephe/nginx_sival.diff
Thanks,
sephe
--
Tomorrow Will Never Die
From pluknet at nginx.com Wed Jan 9 11:52:30 2019
From: pluknet at nginx.com (Sergey Kandaurov)
Date: Wed, 9 Jan 2019 14:52:30 +0300
Subject: aio/unix: Use signal.sival which is standard
In-Reply-To:
References:
Message-ID:
> On 8 Jan 2019, at 06:37, Sepherosa Ziehau wrote:
>
> sigval.sigval is for FreeBSD 6 compability, while FreeBSD 6 was EOL
> for quite a while.
>
> Patch:
> https://leaf.dragonflybsd.org/~sephe/nginx_sival.diff
Citing here for archives:
commit 14d1cab150226367c8a0f0ae219b0e0571587aea
Author: Yanmin Qiao
Date: Tue Jan 8 11:33:00 2019 +0800
unix/aio: Use sigval.sival which is standard.
sigval.sigval is for FreeBSD 6 compability, while FreeBSD 6 was EOL for quite a while.
diff --git a/src/os/unix/ngx_file_aio_read.c b/src/os/unix/ngx_file_aio_read.c
index aedc3c90..bb60ee82 100644
--- a/src/os/unix/ngx_file_aio_read.c
+++ b/src/os/unix/ngx_file_aio_read.c
@@ -110,7 +110,7 @@ ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
#if (NGX_HAVE_KQUEUE)
aio->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
aio->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
- aio->aiocb.aio_sigevent.sigev_value.sigval_ptr = ev;
+ aio->aiocb.aio_sigevent.sigev_value.sival_ptr = ev;
#endif
ev->handler = ngx_file_aio_event_handler;
FreeBSD 4/5/6 lack sival_ptr (FreeBSD 3 has it, but not yet SIGEV_KEVENT),
which seemingly was broken in svn r48621 and later restored in r152029.
And that means that the following will no longer be true:
: Currently file AIO is supported on FreeBSD 4.3+ and Linux 2.6.22+ only
While nginx still maintains compatibility down to FreeBSD 2.2.
If applied, it'd need this part as well (used to build on old FreeBSD):
diff --git a/src/event/modules/ngx_eventport_module.c b/src/event/modules/ngx_eventport_module.c
--- a/src/event/modules/ngx_eventport_module.c
+++ b/src/event/modules/ngx_eventport_module.c
@@ -250,9 +250,7 @@ ngx_eventport_init(ngx_cycle_t *cycle, n
ngx_memzero(&sev, sizeof(struct sigevent));
sev.sigev_notify = SIGEV_PORT;
-#if !(NGX_TEST_BUILD_EVENTPORT)
sev.sigev_value.sival_ptr = &pn;
-#endif
if (timer_create(CLOCK_REALTIME, &sev, &event_timer) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
--
Sergey Kandaurov
From xeioex at nginx.com Wed Jan 9 15:22:42 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Wed, 09 Jan 2019 15:22:42 +0000
Subject: [njs] 2019 year.
Message-ID:
details: https://hg.nginx.org/njs/rev/fd135f1b18bb
branches:
changeset: 713:fd135f1b18bb
user: Dmitry Volyntsev
date: Wed Jan 09 18:21:31 2019 +0300
description:
2019 year.
diffstat:
LICENSE | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diffs (14 lines):
diff -r 74776ba6a1a2 -r fd135f1b18bb LICENSE
--- a/LICENSE Sat Dec 29 22:35:31 2018 +0800
+++ b/LICENSE Wed Jan 09 18:21:31 2019 +0300
@@ -1,7 +1,7 @@
/*
- * Copyright (C) 2015-2018 Igor Sysoev
- * Copyright (C) 2017-2018 Dmitry Volyntsev
- * Copyright (C) 2015-2018 NGINX, Inc.
+ * Copyright (C) 2015-2019 NGINX, Inc.
+ * Copyright (C) 2015-2019 Igor Sysoev
+ * Copyright (C) 2017-2019 Dmitry Volyntsev
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
From xeioex at nginx.com Wed Jan 9 15:22:43 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Wed, 09 Jan 2019 15:22:43 +0000
Subject: [njs] Fixed vmcode function call.
Message-ID:
details: https://hg.nginx.org/njs/rev/d0ba2a63eb5a
branches:
changeset: 714:d0ba2a63eb5a
user: hongzhidao
date: Mon Jan 07 17:40:48 2019 +0800
description:
Fixed vmcode function call.
This closes #82 issue on Github.
diffstat:
njs/njs_vm.c | 10 ++++++++--
njs/test/njs_unit_test.c | 3 +++
2 files changed, 11 insertions(+), 2 deletions(-)
diffs (33 lines):
diff -r fd135f1b18bb -r d0ba2a63eb5a njs/njs_vm.c
--- a/njs/njs_vm.c Wed Jan 09 18:21:31 2019 +0300
+++ b/njs/njs_vm.c Mon Jan 07 17:40:48 2019 +0800
@@ -2086,8 +2086,14 @@ njs_vmcode_function_call(njs_vm_t *vm, n
* If a retval is in a callee arguments scope it
* must be in the previous callee arguments scope.
*/
- vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] =
- vm->top_frame->arguments + function->args_offset;
+ args = vm->top_frame->arguments;
+ function = vm->top_frame->function;
+
+ if (function != NULL) {
+ args += function->args_offset;
+ }
+
+ vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] = args;
retval = njs_vmcode_operand(vm, retval);
/*
diff -r fd135f1b18bb -r d0ba2a63eb5a njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Wed Jan 09 18:21:31 2019 +0300
+++ b/njs/test/njs_unit_test.c Mon Jan 07 17:40:48 2019 +0800
@@ -4017,6 +4017,9 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("var f = ''.concat.bind(0, 1, 2, 3, 4); f(5, 6, 7, 8, 9)"),
nxt_string("0123456789") },
+ { nxt_string("var f = ''.concat.bind(0, 1, 2, 3, 4); f(Math.sqrt(25))"),
+ nxt_string("012345") },
+
{ nxt_string("var f = String.prototype.concat.bind(0, 1); f(2)"),
nxt_string("012") },
From xeioex at nginx.com Wed Jan 9 15:25:12 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Wed, 09 Jan 2019 15:25:12 +0000
Subject: [njs] Refactored njs_function_frame_free.
Message-ID:
details: https://hg.nginx.org/njs/rev/0e7fc17f6071
branches:
changeset: 715:0e7fc17f6071
user: hongzhidao
date: Mon Jan 07 17:42:00 2019 +0800
description:
Refactored njs_function_frame_free.
diffstat:
njs/njs_vm.c | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
diffs (50 lines):
diff -r d0ba2a63eb5a -r 0e7fc17f6071 njs/njs_vm.c
--- a/njs/njs_vm.c Mon Jan 07 17:40:48 2019 +0800
+++ b/njs/njs_vm.c Mon Jan 07 17:42:00 2019 +0800
@@ -38,7 +38,7 @@ static njs_ret_t njs_vmcode_continuation
njs_value_t *invld2);
static njs_native_frame_t *
njs_function_previous_frame(njs_native_frame_t *frame);
-static njs_ret_t njs_function_frame_free(njs_vm_t *vm,
+static void njs_function_frame_free(njs_vm_t *vm,
njs_native_frame_t *frame);
static void njs_vm_trap(njs_vm_t *vm, njs_trap_t trap, njs_value_t *value1,
@@ -2080,7 +2080,7 @@ njs_vmcode_function_call(njs_vm_t *vm, n
frame = vm->top_frame;
vm->top_frame = njs_function_previous_frame(frame);
- (void) njs_function_frame_free(vm, frame);
+ njs_function_frame_free(vm, frame);
/*
* If a retval is in a callee arguments scope it
@@ -2398,7 +2398,9 @@ njs_vmcode_return(njs_vm_t *vm, njs_valu
vm->current = frame->return_address;
- return njs_function_frame_free(vm, &frame->native);
+ njs_function_frame_free(vm, &frame->native);
+
+ return 0;
}
@@ -2544,7 +2546,7 @@ njs_function_previous_frame(njs_native_f
}
-static njs_ret_t
+static void
njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame)
{
njs_native_frame_t *previous;
@@ -2562,8 +2564,6 @@ njs_function_frame_free(njs_vm_t *vm, nj
frame = previous;
} while (frame->skip);
-
- return 0;
}
From mdounin at mdounin.ru Wed Jan 9 19:02:11 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Wed, 9 Jan 2019 22:02:11 +0300
Subject: rate limit request body read from a body filter?
(nginx-upload-module)
In-Reply-To: <7C63024C-E4EE-419E-AFCC-0E29D839C9E7@theatlantic.com>
References: <7C63024C-E4EE-419E-AFCC-0E29D839C9E7@theatlantic.com>
Message-ID: <20190109190211.GV99070@mdounin.ru>
Hello!
On Thu, Jan 03, 2019 at 12:21:15AM -0500, Frankie Dintino wrote:
> I'm currently trying to rewrite
> https://github.com/fdintino/nginx-upload-module/
> as a request
> body filter, in order to simplify the code and future-proof it
> (as it's currently written, there's a lot of copypasta from
> ngx_http_request_body.c that is very fragile and probably
> already incompatible with new features and third party modules).
>
> I'm nearly done this work, but I've hit a stumbling block trying
> to port the upload rate limiting feature. The current
> implementation completely overrides the request handler, so
> rate-limiting the request body is pretty trivial: if you need to
> delay the next buffer read, to stay within the rate limit, you
> can set c->read->delayed = 1, call ngx_add_timer(c->read,
> delay), and return NGX_AGAIN.
>
> When I try this from the request body filter, I'm able to delay
> the very next read event, but afterwards when control is
> returned to the outer request handler, the rate that read
> buffers get consumed is no longer within my control (also,
> returning NGX_AGAIN from the body handler to the http2 request
> handler doesn't work at all?it raises a 500?but that's another
> issue).
>
> So it seems to me that?if I want to keep the upload rate
> limiting feature?I'm going to have to do it somewhere else,
> maybe in a custom read event handler. Is there another option
> I'm not thinking of? And if I have to do it in a custom
> read_event_handler, does anyone have pointers for how I can do
> this in the least obtrusive way?
With HTTP/1.x, I think it should be possible to implement rate
limiting the way you are doing it as long as requests larger than
client_body_buffer_size are concerned - that is, when writing
requests to files. So nginx will read buffers up to
client_body_buffer_size, and writing to a temporary file will be
delayed by your code.
With HTTP/2, I don't think there is a way to implement upload rate
limiting without changes in the HTTP/2 code.
--
Maxim Dounin
http://mdounin.ru/
From msellers at ranchmed.com Wed Jan 9 23:05:22 2019
From: msellers at ranchmed.com (Mark Sellers)
Date: Wed, 9 Jan 2019 15:05:22 -0800
Subject: Confusion about rewritten uri passed to a fastcgi program
Message-ID:
My module (ngx_http_fastimg_module) rewrites the uri of an image request. If the image is not yet in the filesystem, then it (using try_files) calls a fastcgi (fastimg_fcgi) that creates the image, serves it, and saves it in the file system.
I have noticed something that I don?t understand. When the fastcgi program is executed, it receives the original uri in the REQUEST_URI fastcgi param, and not the rewritten uri.
I also notice that the rewritten uri is available in the DOCUMENT_URI fastcgi param.
Is this what you would expect?
Thanks,
Mark
See partial debug log below.
original uri: "/images/12/0/100/0.jpg?
rewritten uri:"/images/21/12_0_100_0.jpg?
?????
2019/01/09 14:33:29 [debug] 19834#0: *1 rewrite phase: 0
2019/01/09 14:33:29 [debug] 19834#0: *1 test location: "/"
2019/01/09 14:33:29 [debug] 19834#0: *1 test location: "images/"
2019/01/09 14:33:29 [debug] 19834#0: *1 using configuration "/images/"
2019/01/09 14:33:29 [debug] 19834#0: *1 http cl:-1 max:104857600
2019/01/09 14:33:29 [debug] 19834#0: *1 rewrite phase: 2
2019/01/09 14:33:29 [debug] 19834#0: *1 fastimg handler
2019/01/09 14:33:29 [debug] 19834#0: *1 ngx_http_fastimg_rewrite() uri in: "/images/12/0/100/0.jpg"
2019/01/09 14:33:29 [debug] 19834#0: *1 ngx_http_fastimg_rewrite() uri out: "/images/21/12_0_100_0.jpg"
2019/01/09 14:33:29 [debug] 19834#0: *1 internal redirect: "/images/21/12_0_100_0.jpg?"
2019/01/09 14:33:29 [debug] 19834#0: *1 rewrite phase: 0
2019/01/09 14:33:29 [debug] 19834#0: *1 test location: "/"
2019/01/09 14:33:29 [debug] 19834#0: *1 test location: "images/"
2019/01/09 14:33:29 [debug] 19834#0: *1 using configuration "/images/"
2019/01/09 14:33:29 [debug] 19834#0: *1 http cl:-1 max:104857600
2019/01/09 14:33:29 [debug] 19834#0: *1 rewrite phase: 2
2019/01/09 14:33:29 [debug] 19834#0: *1 fastimg handler
2019/01/09 14:33:29 [debug] 19834#0: *1 rewrite phase: 3
2019/01/09 14:33:29 [debug] 19834#0: *1 post rewrite phase: 4
2019/01/09 14:33:29 [debug] 19834#0: *1 generic phase: 5
2019/01/09 14:33:29 [debug] 19834#0: *1 generic phase: 6
2019/01/09 14:33:29 [debug] 19834#0: *1 access phase: 7
2019/01/09 14:33:29 [debug] 19834#0: *1 access phase: 8
2019/01/09 14:33:29 [debug] 19834#0: *1 post access phase: 9
2019/01/09 14:33:29 [debug] 19834#0: *1 generic phase: 10
2019/01/09 14:33:29 [debug] 19834#0: *1 try files handler
2019/01/09 14:33:29 [debug] 19834#0: *1 http script var: "/images/21/12_0_100_0.jpg"
2019/01/09 14:33:29 [debug] 19834#0: *1 trying to use file: "/images/21/12_0_100_0.jpg" "/var/www/html/static.ranchmed.com/images/21/12_0_100_0.jpg "
2019/01/09 14:33:29 [debug] 19834#0: *1 trying to use file: "@fastimg_fcgi" "/var/www/html/static.ranchmed.com @fastimg_fcgi"
2019/01/09 14:33:29 [debug] 19834#0: *1 test location: "@fastimg_fcgi"
2019/01/09 14:33:29 [debug] 19834#0: *1 using location: @fastimg_fcgi "/images/21/12_0_100_0.jpg?"
2019/01/09 14:33:29 [debug] 19834#0: *1 rewrite phase: 2
2019/01/09 14:33:29 [debug] 19834#0: *1 fastimg handler
2019/01/09 14:33:29 [debug] 19834#0: *1 rewrite phase: 3
2019/01/09 14:33:29 [debug] 19834#0: *1 post rewrite phase: 4
2019/01/09 14:33:29 [debug] 19834#0: *1 generic phase: 5
2019/01/09 14:33:29 [debug] 19834#0: *1 generic phase: 6
2019/01/09 14:33:29 [debug] 19834#0: *1 access phase: 7
2019/01/09 14:33:29 [debug] 19834#0: *1 access phase: 8
2019/01/09 14:33:29 [debug] 19834#0: *1 post access phase: 9
2019/01/09 14:33:29 [debug] 19834#0: *1 generic phase: 10
2019/01/09 14:33:29 [debug] 19834#0: *1 generic phase: 11
2019/01/09 14:33:29 [debug] 19834#0: *1 http init upstream, client timer: 0
2019/01/09 14:33:29 [debug] 19834#0: *1 epoll add event: fd:17 op:3 ev:80002005
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "QUERY_STRING"
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "QUERY_STRING: "
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "REQUEST_METHOD"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script var: "GET"
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "REQUEST_METHOD: GET"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "CONTENT_TYPE"
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "CONTENT_TYPE: "
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "CONTENT_LENGTH"
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "CONTENT_LENGTH: "
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "SCRIPT_NAME"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script var: "/images/21/12_0_100_0.jpg"
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "SCRIPT_NAME: /images/21/12_0_100_0.jpg"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "REQUEST_URI"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script var: "/images/12/0/100/0.jpg"
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "REQUEST_URI: /images/12/0/100/0.jpg"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "DOCUMENT_URI"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script var: "/images/21/12_0_100_0.jpg"
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "DOCUMENT_URI: /images/21/12_0_100_0.jpg"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "DOCUMENT_ROOT"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script var: "/var/www/html/static.ranchmed.com "
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "DOCUMENT_ROOT: /var/www/html/static.ranchmed.com "
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "SERVER_PROTOCOL"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script var: "HTTP/1.0"
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "SERVER_PROTOCOL: HTTP/1.0"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "REQUEST_SCHEME"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script var: "http"
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "REQUEST_SCHEME: http"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: ""
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "GATEWAY_INTERFACE"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "CGI/1.1"
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "GATEWAY_INTERFACE: CGI/1.1"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "SERVER_SOFTWARE"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "nginx/"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script var: "1.15.7"
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "SERVER_SOFTWARE: nginx/1.15.7"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "REMOTE_ADDR"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script var: "192.168.1.1"
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "REMOTE_ADDR: 192.168.1.1"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "REMOTE_PORT"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script var: "42034"
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "REMOTE_PORT: 42034"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "SERVER_ADDR"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script var: "192.168.1.101"
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "SERVER_ADDR: 192.168.1.101"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "SERVER_PORT"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script var: "80"
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "SERVER_PORT: 80"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "SERVER_NAME"
2019/01/09 14:33:29 [debug] 19834#0: *1 http script var: "dev.static.ranchmed.com "
2019/01/09 14:33:29 [debug] 19835#0: accept() not ready (11: Resource temporarily unavailable)
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "SERVER_NAME: dev.static.ranchmed.com "
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "REDIRECT_STATUS"
2019/01/09 14:33:29 [debug] 19835#0: timer delta: 22583
2019/01/09 14:33:29 [debug] 19834#0: *1 http script copy: "200"
2019/01/09 14:33:29 [debug] 19835#0: worker cycle
2019/01/09 14:33:29 [debug] 19834#0: *1 fastcgi param: "REDIRECT_STATUS: 200"
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From maxim at nginx.com Thu Jan 10 08:30:44 2019
From: maxim at nginx.com (Maxim Konovalov)
Date: Thu, 10 Jan 2019 11:30:44 +0300
Subject: cache: move open to thread pool
In-Reply-To:
References:
<20180808181653.GX56558@mdounin.ru>
<20180810113946.GG56558@mdounin.ru>
<20180903160903.GI56558@mdounin.ru>
<4ba7414a-0eba-6bd3-5a50-2eca591ac25e@nginx.com>
Message-ID: <2a3577f6-4ad4-aa2d-80a2-7e9b715c070d@nginx.com>
So guys, are you really interested in this work beyond shiny
marketing blog posts?
On 05/12/2018 12:43, Maxim Konovalov wrote:
> Hello,
>
> just a reminder that we are looking for a tester for these patches.
>
> Thanks,
>
> Maxim
>
> On 16/11/2018 12:10, Maxim Konovalov wrote:
>> Thanks, Ka-Hing, we'll wait for your feedback.
>>
>> On 16/11/2018 01:53, Ka-Hing Cheung wrote:
>>> Hi,
>>>
>>> I didn't forget about this. I am pretty swamped at the moment and
>>> there's a holiday freeze coming up. Will get to his in December.
>>>
>>> - Ka-Hing
>>>
>>> On Thu, Nov 8, 2018 at 6:19 AM Maxim Konovalov wrote:
>>>>
>>>> Hi Ka-Hing,
>>>>
>>>> would you mind to test Roman's most recent patches that add
>>>> "aio_open" directive?
>>>>
>>>> http://mailman.nginx.org/pipermail/nginx-devel/2018-November/011538.html
>>>>
>>>> We are looking for overall performance and stability metrics and
>>>> feedback.
>>>>
>>>> Much appreciated,
>>>>
>>>> Maxim
>>>>
>>>> --
>>>> Maxim Konovalov
>>
>>
>
>
--
Maxim Konovalov
From xeioex at nginx.com Thu Jan 10 13:08:39 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Thu, 10 Jan 2019 13:08:39 +0000
Subject: [njs] Introduced njs_function_native_call().
Message-ID:
details: https://hg.nginx.org/njs/rev/045ba10db769
branches:
changeset: 716:045ba10db769
user: hongzhidao
date: Mon Jan 07 22:14:17 2019 +0800
description:
Introduced njs_function_native_call().
diffstat:
njs/njs_function.c | 92 ++++++++++++++++++++++++++++++++++
njs/njs_function.h | 4 +
njs/njs_vm.c | 140 ++++++----------------------------------------------
3 files changed, 113 insertions(+), 123 deletions(-)
diffs (304 lines):
diff -r 0e7fc17f6071 -r 045ba10db769 njs/njs_function.c
--- a/njs/njs_function.c Mon Jan 07 17:42:00 2019 +0800
+++ b/njs/njs_function.c Mon Jan 07 22:14:17 2019 +0800
@@ -531,6 +531,98 @@ njs_function_call(njs_vm_t *vm, njs_inde
}
+njs_ret_t
+njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
+ njs_value_t *args, nxt_uint_t nargs, njs_index_t retval)
+{
+ njs_ret_t ret;
+ njs_value_t *value;
+ njs_function_t *function;
+ njs_native_frame_t *frame;
+
+ ret = native(vm, args, nargs, retval);
+
+ /*
+ * A native method can return:
+ * NXT_OK on method success;
+ * NJS_APPLIED by Function.apply() and Function.call();
+ * NXT_AGAIN to postpone nJSVM processing;
+ * NXT_ERROR.
+ *
+ * The callee arguments must be preserved
+ * for NJS_APPLIED and NXT_AGAIN cases.
+ */
+ if (ret == NXT_OK) {
+ frame = vm->top_frame;
+
+ vm->top_frame = njs_function_previous_frame(frame);
+ njs_function_frame_free(vm, frame);
+
+ /*
+ * If a retval is in a callee arguments scope it
+ * must be in the previous callee arguments scope.
+ */
+ args = vm->top_frame->arguments;
+ function = vm->top_frame->function;
+
+ if (function != NULL) {
+ args += function->args_offset;
+ }
+
+ vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] = args;
+
+ if (!frame->skip) {
+ value = njs_vmcode_operand(vm, retval);
+ /*
+ * GC: value external/internal++ depending
+ * on vm->retval and retval type
+ */
+ *value = vm->retval;
+ }
+
+ return NXT_OK;
+ }
+
+ return ret;
+}
+
+
+njs_native_frame_t *
+njs_function_previous_frame(njs_native_frame_t *frame)
+{
+ njs_native_frame_t *previous;
+
+ do {
+ previous = frame->previous;
+ frame = previous;
+
+ } while (frame->skip);
+
+ return frame;
+}
+
+
+void
+njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame)
+{
+ njs_native_frame_t *previous;
+
+ do {
+ previous = frame->previous;
+
+ /* GC: free frame->local, etc. */
+
+ if (frame->size != 0) {
+ vm->stack_size -= frame->size;
+ nxt_mem_cache_free(vm->mem_cache_pool, frame);
+ }
+
+ frame = previous;
+
+ } while (frame->skip);
+}
+
+
/*
* The "prototype" property of user defined functions is created on
* demand in private hash of the functions by the "prototype" getter.
diff -r 0e7fc17f6071 -r 045ba10db769 njs/njs_function.h
--- a/njs/njs_function.h Mon Jan 07 17:42:00 2019 +0800
+++ b/njs/njs_function.h Mon Jan 07 22:14:17 2019 +0800
@@ -171,6 +171,10 @@ njs_ret_t njs_function_frame(njs_vm_t *v
const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
nxt_bool_t ctor);
njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
+njs_ret_t njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
+ njs_value_t *args, nxt_uint_t nargs, njs_index_t retval);
+njs_native_frame_t *njs_function_previous_frame(njs_native_frame_t *frame);
+void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
extern const njs_object_init_t njs_function_constructor_init;
extern const njs_object_init_t njs_function_prototype_init;
diff -r 0e7fc17f6071 -r 045ba10db769 njs/njs_vm.c
--- a/njs/njs_vm.c Mon Jan 07 17:42:00 2019 +0800
+++ b/njs/njs_vm.c Mon Jan 07 22:14:17 2019 +0800
@@ -36,10 +36,6 @@ static void njs_vm_scopes_restore(njs_vm
njs_native_frame_t *previous);
static njs_ret_t njs_vmcode_continuation(njs_vm_t *vm, njs_value_t *invld1,
njs_value_t *invld2);
-static njs_native_frame_t *
- njs_function_previous_frame(njs_native_frame_t *frame);
-static void njs_function_frame_free(njs_vm_t *vm,
- njs_native_frame_t *frame);
static void njs_vm_trap(njs_vm_t *vm, njs_trap_t trap, njs_value_t *value1,
njs_value_t *value2);
@@ -2064,52 +2060,19 @@ njs_vmcode_function_call(njs_vm_t *vm, n
return 0;
}
- ret = function->u.native(vm, args, nargs, (njs_index_t) retval);
-
- /*
- * A native method can return:
- * NXT_OK on method success;
- * NJS_APPLIED by Function.apply() and Function.call();
- * NXT_AGAIN to postpone nJSVM processing;
- * NXT_ERROR.
- *
- * The callee arguments must be preserved
- * for NJS_APPLIED and NXT_AGAIN cases.
- */
- if (ret == NXT_OK) {
- frame = vm->top_frame;
-
- vm->top_frame = njs_function_previous_frame(frame);
- njs_function_frame_free(vm, frame);
-
- /*
- * If a retval is in a callee arguments scope it
- * must be in the previous callee arguments scope.
- */
- args = vm->top_frame->arguments;
- function = vm->top_frame->function;
-
- if (function != NULL) {
- args += function->args_offset;
- }
-
- vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] = args;
-
- retval = njs_vmcode_operand(vm, retval);
- /*
- * GC: value external/internal++ depending
- * on vm->retval and retval type
- */
- *retval = vm->retval;
-
- ret = sizeof(njs_vmcode_function_call_t);
-
- } else if (ret == NJS_APPLIED) {
- /* A user-defined method has been prepared to run. */
- ret = 0;
+ ret = njs_function_native_call(vm, function->u.native, args, nargs,
+ (njs_index_t) retval);
+
+ switch (ret) {
+ case NXT_OK:
+ return sizeof(njs_vmcode_function_call_t);
+
+ case NJS_APPLIED:
+ return 0;
+
+ default:
+ return ret;
}
-
- return ret;
}
@@ -2467,60 +2430,27 @@ static njs_ret_t
njs_vmcode_continuation(njs_vm_t *vm, njs_value_t *invld1, njs_value_t *invld2)
{
njs_ret_t ret;
- nxt_bool_t skip;
- njs_value_t *args, *retval;
- njs_function_t *function;
njs_native_frame_t *frame;
njs_continuation_t *cont;
cont = njs_vm_continuation(vm);
frame = vm->top_frame;
- args = frame->arguments;
if (cont->args_types != NULL) {
- ret = njs_normalize_args(vm, args, cont->args_types, frame->nargs);
+ ret = njs_normalize_args(vm, frame->arguments, cont->args_types,
+ frame->nargs);
if (ret != NJS_OK) {
return ret;
}
}
- ret = cont->function(vm, args, frame->nargs, cont->retval);
+ ret = njs_function_native_call(vm, cont->function, frame->arguments,
+ frame->nargs, cont->retval);
switch (ret) {
-
case NXT_OK:
-
- frame = vm->top_frame;
- skip = frame->skip;
-
- vm->top_frame = njs_function_previous_frame(frame);
-
- /*
- * If a retval is in a callee arguments scope it
- * must be in the previous callee arguments scope.
- */
- args = vm->top_frame->arguments;
- function = vm->top_frame->function;
-
- if (function != NULL) {
- args += function->args_offset;
- }
-
- vm->scopes[NJS_SCOPE_CALLEE_ARGUMENTS] = args;
-
- if (!skip) {
- retval = njs_vmcode_operand(vm, cont->retval);
- /*
- * GC: value external/internal++ depending
- * on vm->retval and retval type
- */
- *retval = vm->retval;
- }
-
vm->current = cont->return_address;
- (void) njs_function_frame_free(vm, frame);
-
- return 0;
+ /* Fall through. */
case NJS_APPLIED:
return 0;
@@ -2531,42 +2461,6 @@ njs_vmcode_continuation(njs_vm_t *vm, nj
}
-static njs_native_frame_t *
-njs_function_previous_frame(njs_native_frame_t *frame)
-{
- njs_native_frame_t *previous;
-
- do {
- previous = frame->previous;
- frame = previous;
-
- } while (frame->skip);
-
- return frame;
-}
-
-
-static void
-njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame)
-{
- njs_native_frame_t *previous;
-
- do {
- previous = frame->previous;
-
- /* GC: free frame->local, etc. */
-
- if (frame->size != 0) {
- vm->stack_size -= frame->size;
- nxt_mem_cache_free(vm->mem_cache_pool, frame);
- }
-
- frame = previous;
-
- } while (frame->skip);
-}
-
-
njs_ret_t
njs_vmcode_stop(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval)
{
From mdounin at mdounin.ru Thu Jan 10 13:19:13 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Thu, 10 Jan 2019 16:19:13 +0300
Subject: Confusion about rewritten uri passed to a fastcgi program
In-Reply-To:
References:
Message-ID: <20190110131913.GX99070@mdounin.ru>
Hello!
On Wed, Jan 09, 2019 at 03:05:22PM -0800, Mark Sellers wrote:
>
> My module (ngx_http_fastimg_module) rewrites the uri of an image request. If the image is not yet in the filesystem, then it (using try_files) calls a fastcgi (fastimg_fcgi) that creates the image, serves it, and saves it in the file system.
>
> I have noticed something that I don?t understand. When the fastcgi program is executed, it receives the original uri in the REQUEST_URI fastcgi param, and not the rewritten uri.
>
> I also notice that the rewritten uri is available in the DOCUMENT_URI fastcgi param.
>
> Is this what you would expect?
What is sent in FastCGI parameters is determined by the
fastcgi_param directives used in your configuration, see
http://nginx.org/r/fastcgi_param. The example/default
fastcgi_params file as shipped with nginx contains
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
so the REQUEST_URI param will get the original URI as sent by the
client, and the rewritten URI will be available in DOCUMENT_URI,
exactly as your observe.
--
Maxim Dounin
http://mdounin.ru/
From xeioex at nginx.com Thu Jan 10 14:31:00 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Thu, 10 Jan 2019 14:31:00 +0000
Subject: [njs] Moving njs_normalize_args() into njs_function_native_call().
Message-ID:
details: https://hg.nginx.org/njs/rev/0da53bc8472b
branches:
changeset: 717:0da53bc8472b
user: hongzhidao
date: Tue Jan 08 04:04:02 2019 +0800
description:
Moving njs_normalize_args() into njs_function_native_call().
diffstat:
njs/njs_function.c | 144 ++++++++++++++++++++++++++++++++++++++++++++++++-
njs/njs_function.h | 3 +-
njs/njs_vm.c | 155 +---------------------------------------------------
njs/njs_vm.h | 2 -
4 files changed, 150 insertions(+), 154 deletions(-)
diffs (388 lines):
diff -r 045ba10db769 -r 0da53bc8472b njs/njs_function.c
--- a/njs/njs_function.c Mon Jan 07 22:14:17 2019 +0800
+++ b/njs/njs_function.c Tue Jan 08 04:04:02 2019 +0800
@@ -8,6 +8,8 @@
#include
+static njs_ret_t njs_normalize_args(njs_vm_t *vm, njs_value_t *args,
+ uint8_t *args_types, nxt_uint_t nargs);
static njs_ret_t njs_function_activate(njs_vm_t *vm, njs_function_t *function,
njs_value_t *this, njs_value_t *args, nxt_uint_t nargs, njs_index_t retval);
@@ -533,13 +535,19 @@ njs_function_call(njs_vm_t *vm, njs_inde
njs_ret_t
njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t retval)
+ njs_value_t *args, uint8_t *args_types, nxt_uint_t nargs,
+ njs_index_t retval)
{
njs_ret_t ret;
njs_value_t *value;
njs_function_t *function;
njs_native_frame_t *frame;
+ ret = njs_normalize_args(vm, args, args_types, nargs);
+ if (ret != NJS_OK) {
+ return ret;
+ }
+
ret = native(vm, args, nargs, retval);
/*
@@ -587,6 +595,140 @@ njs_function_native_call(njs_vm_t *vm, n
}
+static njs_ret_t
+njs_normalize_args(njs_vm_t *vm, njs_value_t *args, uint8_t *args_types,
+ nxt_uint_t nargs)
+{
+ nxt_uint_t n;
+ njs_trap_t trap;
+
+ n = nxt_min(nargs, NJS_ARGS_TYPES_MAX);
+
+ while (n != 0) {
+
+ switch (*args_types) {
+
+ case NJS_STRING_OBJECT_ARG:
+
+ if (njs_is_null_or_void(args)) {
+ goto type_error;
+ }
+
+ /* Fall through. */
+
+ case NJS_STRING_ARG:
+
+ if (njs_is_string(args)) {
+ break;
+ }
+
+ trap = NJS_TRAP_STRING_ARG;
+ goto trap;
+
+ case NJS_NUMBER_ARG:
+
+ if (njs_is_numeric(args)) {
+ break;
+ }
+
+ trap = NJS_TRAP_NUMBER_ARG;
+ goto trap;
+
+ case NJS_INTEGER_ARG:
+
+ if (njs_is_numeric(args)) {
+
+ /* Numbers are truncated to fit in 32-bit integers. */
+
+ if (isnan(args->data.u.number)) {
+ args->data.u.number = 0;
+
+ } else if (args->data.u.number > 2147483647.0) {
+ args->data.u.number = 2147483647.0;
+
+ } else if (args->data.u.number < -2147483648.0) {
+ args->data.u.number = -2147483648.0;
+ }
+
+ break;
+ }
+
+ trap = NJS_TRAP_NUMBER_ARG;
+ goto trap;
+
+ case NJS_FUNCTION_ARG:
+
+ switch (args->type) {
+ case NJS_STRING:
+ case NJS_FUNCTION:
+ break;
+
+ default:
+ trap = NJS_TRAP_STRING_ARG;
+ goto trap;
+ }
+
+ break;
+
+ case NJS_REGEXP_ARG:
+
+ switch (args->type) {
+ case NJS_VOID:
+ case NJS_STRING:
+ case NJS_REGEXP:
+ break;
+
+ default:
+ trap = NJS_TRAP_STRING_ARG;
+ goto trap;
+ }
+
+ break;
+
+ case NJS_DATE_ARG:
+ if (!njs_is_date(args)) {
+ goto type_error;
+ }
+
+ break;
+
+ case NJS_OBJECT_ARG:
+
+ if (njs_is_null_or_void(args)) {
+ goto type_error;
+ }
+
+ break;
+
+ case NJS_SKIP_ARG:
+ break;
+
+ case 0:
+ return NJS_OK;
+ }
+
+ args++;
+ args_types++;
+ n--;
+ }
+
+ return NJS_OK;
+
+trap:
+
+ njs_vm_trap_value(vm, args);
+
+ return njs_trap(vm, trap);
+
+type_error:
+
+ njs_type_error(vm, "cannot convert %s to %s", njs_type_string(args->type),
+ njs_arg_type_string(*args_types));
+
+ return NXT_ERROR;
+}
+
+
njs_native_frame_t *
njs_function_previous_frame(njs_native_frame_t *frame)
{
diff -r 045ba10db769 -r 0da53bc8472b njs/njs_function.h
--- a/njs/njs_function.h Mon Jan 07 22:14:17 2019 +0800
+++ b/njs/njs_function.h Tue Jan 08 04:04:02 2019 +0800
@@ -172,7 +172,8 @@ njs_ret_t njs_function_frame(njs_vm_t *v
nxt_bool_t ctor);
njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
njs_ret_t njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t retval);
+ njs_value_t *args, uint8_t *args_types, nxt_uint_t nargs,
+ njs_index_t retval);
njs_native_frame_t *njs_function_previous_frame(njs_native_frame_t *frame);
void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
diff -r 045ba10db769 -r 0da53bc8472b njs/njs_vm.c
--- a/njs/njs_vm.c Mon Jan 07 22:14:17 2019 +0800
+++ b/njs/njs_vm.c Tue Jan 08 04:04:02 2019 +0800
@@ -2042,11 +2042,6 @@ njs_vmcode_function_call(njs_vm_t *vm, n
args = frame->arguments;
nargs = frame->nargs;
- ret = njs_normalize_args(vm, args, function->args_types, nargs);
- if (ret != NJS_OK) {
- return ret;
- }
-
if (function->continuation_size != 0) {
cont = njs_vm_continuation(vm);
@@ -2060,7 +2055,8 @@ njs_vmcode_function_call(njs_vm_t *vm, n
return 0;
}
- ret = njs_function_native_call(vm, function->u.native, args, nargs,
+ ret = njs_function_native_call(vm, function->u.native, args,
+ function->args_types, nargs,
(njs_index_t) retval);
switch (ret) {
@@ -2076,140 +2072,6 @@ njs_vmcode_function_call(njs_vm_t *vm, n
}
-njs_ret_t
-njs_normalize_args(njs_vm_t *vm, njs_value_t *args, uint8_t *args_types,
- nxt_uint_t nargs)
-{
- nxt_uint_t n;
- njs_trap_t trap;
-
- n = nxt_min(nargs, NJS_ARGS_TYPES_MAX);
-
- while (n != 0) {
-
- switch (*args_types) {
-
- case NJS_STRING_OBJECT_ARG:
-
- if (njs_is_null_or_void(args)) {
- goto type_error;
- }
-
- /* Fall through. */
-
- case NJS_STRING_ARG:
-
- if (njs_is_string(args)) {
- break;
- }
-
- trap = NJS_TRAP_STRING_ARG;
- goto trap;
-
- case NJS_NUMBER_ARG:
-
- if (njs_is_numeric(args)) {
- break;
- }
-
- trap = NJS_TRAP_NUMBER_ARG;
- goto trap;
-
- case NJS_INTEGER_ARG:
-
- if (njs_is_numeric(args)) {
-
- /* Numbers are truncated to fit in 32-bit integers. */
-
- if (isnan(args->data.u.number)) {
- args->data.u.number = 0;
-
- } else if (args->data.u.number > 2147483647.0) {
- args->data.u.number = 2147483647.0;
-
- } else if (args->data.u.number < -2147483648.0) {
- args->data.u.number = -2147483648.0;
- }
-
- break;
- }
-
- trap = NJS_TRAP_NUMBER_ARG;
- goto trap;
-
- case NJS_FUNCTION_ARG:
-
- switch (args->type) {
- case NJS_STRING:
- case NJS_FUNCTION:
- break;
-
- default:
- trap = NJS_TRAP_STRING_ARG;
- goto trap;
- }
-
- break;
-
- case NJS_REGEXP_ARG:
-
- switch (args->type) {
- case NJS_VOID:
- case NJS_STRING:
- case NJS_REGEXP:
- break;
-
- default:
- trap = NJS_TRAP_STRING_ARG;
- goto trap;
- }
-
- break;
-
- case NJS_DATE_ARG:
- if (!njs_is_date(args)) {
- goto type_error;
- }
-
- break;
-
- case NJS_OBJECT_ARG:
-
- if (njs_is_null_or_void(args)) {
- goto type_error;
- }
-
- break;
-
- case NJS_SKIP_ARG:
- break;
-
- case 0:
- return NJS_OK;
- }
-
- args++;
- args_types++;
- n--;
- }
-
- return NJS_OK;
-
-trap:
-
- njs_vm_trap_value(vm, args);
-
- return njs_trap(vm, trap);
-
-type_error:
-
- njs_type_error(vm, "cannot convert %s to %s", njs_type_string(args->type),
- njs_arg_type_string(*args_types));
-
- return NXT_ERROR;
-}
-
-
const char *
njs_type_string(njs_value_type_t type)
{
@@ -2433,19 +2295,12 @@ njs_vmcode_continuation(njs_vm_t *vm, nj
njs_native_frame_t *frame;
njs_continuation_t *cont;
+ frame = vm->top_frame;
cont = njs_vm_continuation(vm);
- frame = vm->top_frame;
-
- if (cont->args_types != NULL) {
- ret = njs_normalize_args(vm, frame->arguments, cont->args_types,
- frame->nargs);
- if (ret != NJS_OK) {
- return ret;
- }
- }
ret = njs_function_native_call(vm, cont->function, frame->arguments,
- frame->nargs, cont->retval);
+ cont->args_types, frame->nargs,
+ cont->retval);
switch (ret) {
case NXT_OK:
diff -r 045ba10db769 -r 0da53bc8472b njs/njs_vm.h
--- a/njs/njs_vm.h Mon Jan 07 22:14:17 2019 +0800
+++ b/njs/njs_vm.h Tue Jan 08 04:04:02 2019 +0800
@@ -1262,8 +1262,6 @@ njs_ret_t njs_vmcode_finally(njs_vm_t *v
nxt_bool_t njs_values_strict_equal(const njs_value_t *val1,
const njs_value_t *val2);
-njs_ret_t njs_normalize_args(njs_vm_t *vm, njs_value_t *args,
- uint8_t *args_types, nxt_uint_t nargs);
const char *njs_type_string(njs_value_type_t type);
const char *njs_arg_type_string(uint8_t arg);
From xeioex at nginx.com Thu Jan 10 14:31:01 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Thu, 10 Jan 2019 14:31:01 +0000
Subject: [njs] Inlined njs_function_previous_frame().
Message-ID:
details: https://hg.nginx.org/njs/rev/57b89039ff23
branches:
changeset: 718:57b89039ff23
user: Dmitry Volyntsev
date: Thu Jan 10 17:30:30 2019 +0300
description:
Inlined njs_function_previous_frame().
diffstat:
njs/njs_function.c | 15 ---------------
njs/njs_function.h | 17 ++++++++++++++++-
2 files changed, 16 insertions(+), 16 deletions(-)
diffs (54 lines):
diff -r 0da53bc8472b -r 57b89039ff23 njs/njs_function.c
--- a/njs/njs_function.c Tue Jan 08 04:04:02 2019 +0800
+++ b/njs/njs_function.c Thu Jan 10 17:30:30 2019 +0300
@@ -729,21 +729,6 @@ type_error:
}
-njs_native_frame_t *
-njs_function_previous_frame(njs_native_frame_t *frame)
-{
- njs_native_frame_t *previous;
-
- do {
- previous = frame->previous;
- frame = previous;
-
- } while (frame->skip);
-
- return frame;
-}
-
-
void
njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame)
{
diff -r 0da53bc8472b -r 57b89039ff23 njs/njs_function.h
--- a/njs/njs_function.h Tue Jan 08 04:04:02 2019 +0800
+++ b/njs/njs_function.h Thu Jan 10 17:30:30 2019 +0300
@@ -174,9 +174,24 @@ njs_ret_t njs_function_call(njs_vm_t *vm
njs_ret_t njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
njs_value_t *args, uint8_t *args_types, nxt_uint_t nargs,
njs_index_t retval);
-njs_native_frame_t *njs_function_previous_frame(njs_native_frame_t *frame);
void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
+
+nxt_inline njs_native_frame_t *
+njs_function_previous_frame(njs_native_frame_t *frame)
+{
+ njs_native_frame_t *previous;
+
+ do {
+ previous = frame->previous;
+ frame = previous;
+
+ } while (frame->skip);
+
+ return frame;
+}
+
+
extern const njs_object_init_t njs_function_constructor_init;
extern const njs_object_init_t njs_function_prototype_init;
From xeioex at nginx.com Thu Jan 10 16:00:52 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Thu, 10 Jan 2019 16:00:52 +0000
Subject: [njs] Simplified njs_vm_call().
Message-ID:
details: https://hg.nginx.org/njs/rev/5da4da7386a8
branches:
changeset: 720:5da4da7386a8
user: hongzhidao
date: Tue Jan 08 05:02:20 2019 +0800
description:
Simplified njs_vm_call().
diffstat:
njs/njs.c | 6 +-----
1 files changed, 1 insertions(+), 5 deletions(-)
diffs (19 lines):
diff -r 6ee587abd958 -r 5da4da7386a8 njs/njs.c
--- a/njs/njs.c Tue Jan 08 04:11:51 2019 +0800
+++ b/njs/njs.c Tue Jan 08 05:02:20 2019 +0800
@@ -479,14 +479,10 @@ njs_vm_call(njs_vm_t *vm, njs_function_t
return ret;
}
- ret = njs_vmcode_interpreter(vm);
+ ret = njs_vm_start(vm);
vm->current = current;
- if (ret == NJS_STOP) {
- ret = NXT_OK;
- }
-
return ret;
}
From xeioex at nginx.com Thu Jan 10 16:00:51 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Thu, 10 Jan 2019 16:00:51 +0000
Subject: [njs] Making njs_function_activate() more generic.
Message-ID:
details: https://hg.nginx.org/njs/rev/6ee587abd958
branches:
changeset: 719:6ee587abd958
user: hongzhidao
date: Tue Jan 08 04:11:51 2019 +0800
description:
Making njs_function_activate() more generic.
diffstat:
njs/njs.c | 46 +++++++++-------------------------------------
njs/njs_function.c | 43 ++++++++++++++++++++++++++++---------------
njs/njs_function.h | 3 +++
njs/njs_vm.c | 7 ++++++-
njs/njs_vm.h | 2 +-
5 files changed, 47 insertions(+), 54 deletions(-)
diffs (213 lines):
diff -r 57b89039ff23 -r 6ee587abd958 njs/njs.c
--- a/njs/njs.c Thu Jan 10 17:30:30 2019 +0300
+++ b/njs/njs.c Tue Jan 08 04:11:51 2019 +0800
@@ -461,50 +461,22 @@ nxt_int_t
njs_vm_call(njs_vm_t *vm, njs_function_t *function, const njs_value_t *args,
nxt_uint_t nargs)
{
- u_char *current;
- njs_ret_t ret;
- njs_value_t *this;
- njs_continuation_t *cont;
-
- static const njs_vmcode_stop_t stop[] = {
- { .code = { .operation = njs_vmcode_stop,
- .operands = NJS_VMCODE_1OPERAND,
- .retval = NJS_VMCODE_NO_RETVAL },
- .retval = NJS_INDEX_GLOBAL_RETVAL },
- };
+ u_char *current;
+ njs_ret_t ret;
+ njs_value_t *this;
this = (njs_value_t *) &njs_value_void;
current = vm->current;
- if (function->native) {
- ret = njs_function_native_frame(vm, function, this, &args[0],
- nargs, NJS_CONTINUATION_SIZE, 0);
- if (ret != NJS_OK) {
- return NJS_ERROR;
- }
-
- cont = njs_vm_continuation(vm);
-
- cont->function = function->u.native;
- cont->args_types = function->args_types;
- cont->retval = NJS_INDEX_GLOBAL_RETVAL;
+ vm->current = (u_char *) njs_continuation_nexus;
- cont->return_address = (u_char *) stop;
- vm->current = (u_char *) njs_continuation_nexus;
+ ret = njs_function_activate(vm, function, this, args, nargs,
+ NJS_INDEX_GLOBAL_RETVAL,
+ sizeof(njs_vmcode_generic_t));
- } else {
- ret = njs_function_frame(vm, function, this, args, nargs, 0);
- if (nxt_slow_path(ret != NXT_OK)) {
- return ret;
- }
-
- vm->current = (u_char *) stop;
-
- ret = njs_function_call(vm, NJS_INDEX_GLOBAL_RETVAL, 0);
- if (nxt_slow_path(ret == NXT_ERROR)) {
- return ret;
- }
+ if (nxt_slow_path(ret == NXT_ERROR)) {
+ return ret;
}
ret = njs_vmcode_interpreter(vm);
diff -r 57b89039ff23 -r 6ee587abd958 njs/njs_function.c
--- a/njs/njs_function.c Thu Jan 10 17:30:30 2019 +0300
+++ b/njs/njs_function.c Tue Jan 08 04:11:51 2019 +0800
@@ -10,8 +10,6 @@
static njs_ret_t njs_normalize_args(njs_vm_t *vm, njs_value_t *args,
uint8_t *args_types, nxt_uint_t nargs);
-static njs_ret_t njs_function_activate(njs_vm_t *vm, njs_function_t *function,
- njs_value_t *this, njs_value_t *args, nxt_uint_t nargs, njs_index_t retval);
njs_function_t *
@@ -897,6 +895,7 @@ static njs_ret_t
njs_function_prototype_call(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t retval)
{
+ njs_ret_t ret;
njs_value_t *this;
njs_function_t *function;
@@ -916,7 +915,16 @@ njs_function_prototype_call(njs_vm_t *vm
function = args[0].data.u.function;
- return njs_function_activate(vm, function, this, &args[2], nargs, retval);
+ ret = njs_function_activate(vm, function, this, &args[2], nargs, retval,
+ sizeof(njs_vmcode_function_call_t));
+ if (nxt_slow_path(ret == NXT_ERROR)) {
+ return ret;
+ }
+
+ /* Skip the "call" method frame. */
+ vm->top_frame->previous->skip = 1;
+
+ return NJS_APPLIED;
}
@@ -924,6 +932,7 @@ static njs_ret_t
njs_function_prototype_apply(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t retval)
{
+ njs_ret_t ret;
njs_array_t *array;
njs_value_t *this;
njs_function_t *function;
@@ -954,13 +963,24 @@ njs_function_prototype_apply(njs_vm_t *v
nargs = 0;
}
- return njs_function_activate(vm, function, this, args, nargs, retval);
+ ret = njs_function_activate(vm, function, this, args, nargs, retval,
+ sizeof(njs_vmcode_function_call_t));
+
+ if (nxt_slow_path(ret == NXT_ERROR)) {
+ return ret;
+ }
+
+ /* Skip the "apply" method frame. */
+ vm->top_frame->previous->skip = 1;
+
+ return NJS_APPLIED;
}
-static njs_ret_t
+njs_ret_t
njs_function_activate(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t retval)
+ const njs_value_t *args, nxt_uint_t nargs, njs_index_t retval,
+ size_t advance)
{
njs_ret_t ret;
njs_continuation_t *cont;
@@ -972,17 +992,13 @@ njs_function_activate(njs_vm_t *vm, njs_
return ret;
}
- /* Skip the "call/apply" method frame. */
- vm->top_frame->previous->skip = 1;
-
cont = njs_vm_continuation(vm);
cont->function = function->u.native;
cont->args_types = function->args_types;
cont->retval = retval;
- cont->return_address = vm->current
- + sizeof(njs_vmcode_function_call_t);
+ cont->return_address = vm->current + advance;
vm->current = (u_char *) njs_continuation_nexus;
return NJS_APPLIED;
@@ -994,10 +1010,7 @@ njs_function_activate(njs_vm_t *vm, njs_
return ret;
}
- /* Skip the "call/apply" method frame. */
- vm->top_frame->previous->skip = 1;
-
- return njs_function_call(vm, retval, sizeof(njs_vmcode_function_call_t));
+ return njs_function_call(vm, retval, advance);
}
diff -r 57b89039ff23 -r 6ee587abd958 njs/njs_function.h
--- a/njs/njs_function.h Thu Jan 10 17:30:30 2019 +0300
+++ b/njs/njs_function.h Tue Jan 08 04:11:51 2019 +0800
@@ -170,6 +170,9 @@ njs_ret_t njs_function_native_frame(njs_
njs_ret_t njs_function_frame(njs_vm_t *vm, njs_function_t *function,
const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
nxt_bool_t ctor);
+njs_ret_t njs_function_activate(njs_vm_t *vm, njs_function_t *function,
+ njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t retval, size_t advance);
njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
njs_ret_t njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
njs_value_t *args, uint8_t *args_types, nxt_uint_t nargs,
diff -r 57b89039ff23 -r 6ee587abd958 njs/njs_vm.c
--- a/njs/njs_vm.c Thu Jan 10 17:30:30 2019 +0300
+++ b/njs/njs_vm.c Tue Jan 08 04:11:51 2019 +0800
@@ -2281,10 +2281,15 @@ njs_vm_scopes_restore(njs_vm_t *vm, njs_
}
-const njs_vmcode_1addr_t njs_continuation_nexus[] = {
+const njs_vmcode_generic_t njs_continuation_nexus[] = {
{ .code = { .operation = njs_vmcode_continuation,
.operands = NJS_VMCODE_NO_OPERAND,
.retval = NJS_VMCODE_NO_RETVAL } },
+
+ { .code = { .operation = njs_vmcode_stop,
+ .operands = NJS_VMCODE_1OPERAND,
+ .retval = NJS_VMCODE_NO_RETVAL },
+ .operand1 = NJS_INDEX_GLOBAL_RETVAL },
};
diff -r 57b89039ff23 -r 6ee587abd958 njs/njs_vm.h
--- a/njs/njs_vm.h Thu Jan 10 17:30:30 2019 +0300
+++ b/njs/njs_vm.h Tue Jan 08 04:11:51 2019 +0800
@@ -1304,7 +1304,7 @@ extern const njs_value_t njs_string_mem
extern const nxt_mem_proto_t njs_array_mem_proto;
extern const nxt_lvlhsh_proto_t njs_object_hash_proto;
-extern const njs_vmcode_1addr_t njs_continuation_nexus[];
+extern const njs_vmcode_generic_t njs_continuation_nexus[];
#endif /* _NJS_VM_H_INCLUDED_ */
From xeioex at nginx.com Thu Jan 10 16:00:52 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Thu, 10 Jan 2019 16:00:52 +0000
Subject: [njs] Fixed njs_vm_call().
Message-ID:
details: https://hg.nginx.org/njs/rev/d357ff6b4fe3
branches:
changeset: 721:d357ff6b4fe3
user: hongzhidao
date: Tue Jan 08 06:14:36 2019 +0800
description:
Fixed njs_vm_call().
diffstat:
njs/njs.c | 6 ++----
1 files changed, 2 insertions(+), 4 deletions(-)
diffs (18 lines):
diff -r 5da4da7386a8 -r d357ff6b4fe3 njs/njs.c
--- a/njs/njs.c Tue Jan 08 05:02:20 2019 +0800
+++ b/njs/njs.c Tue Jan 08 06:14:36 2019 +0800
@@ -475,12 +475,10 @@ njs_vm_call(njs_vm_t *vm, njs_function_t
NJS_INDEX_GLOBAL_RETVAL,
sizeof(njs_vmcode_generic_t));
- if (nxt_slow_path(ret == NXT_ERROR)) {
- return ret;
+ if (nxt_fast_path(ret == NJS_APPLIED)) {
+ ret = njs_vm_start(vm);
}
- ret = njs_vm_start(vm);
-
vm->current = current;
return ret;
From xeioex at nginx.com Thu Jan 10 16:00:52 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Thu, 10 Jan 2019 16:00:52 +0000
Subject: [njs] Refactored out njs_function_apply().
Message-ID:
details: https://hg.nginx.org/njs/rev/7029ec713458
branches:
changeset: 722:7029ec713458
user: hongzhidao
date: Tue Jan 08 06:14:36 2019 +0800
description:
Refactored out njs_function_apply().
As a variant of njs_function_activate().
diffstat:
njs/njs_function.c | 42 +++---------------------------------------
njs/njs_function.h | 13 ++++++++++---
2 files changed, 13 insertions(+), 42 deletions(-)
diffs (96 lines):
diff -r d357ff6b4fe3 -r 7029ec713458 njs/njs_function.c
--- a/njs/njs_function.c Tue Jan 08 06:14:36 2019 +0800
+++ b/njs/njs_function.c Tue Jan 08 06:14:36 2019 +0800
@@ -393,42 +393,6 @@ njs_function_frame_alloc(njs_vm_t *vm, s
nxt_noinline njs_ret_t
-njs_function_apply(njs_vm_t *vm, njs_function_t *function, njs_value_t *args,
- nxt_uint_t nargs, njs_index_t retval)
-{
- njs_ret_t ret;
- njs_continuation_t *cont;
-
- if (function->native) {
- ret = njs_function_native_frame(vm, function, &args[0], &args[1],
- nargs - 1, NJS_CONTINUATION_SIZE, 0);
- if (ret != NJS_OK) {
- return ret;
- }
-
- cont = njs_vm_continuation(vm);
-
- cont->function = function->u.native;
- cont->args_types = function->args_types;
- cont->retval = retval;
-
- cont->return_address = vm->current;
- vm->current = (u_char *) njs_continuation_nexus;
-
- return NJS_APPLIED;
- }
-
- ret = njs_function_frame(vm, function, &args[0], &args[1], nargs - 1, 0);
-
- if (nxt_fast_path(ret == NXT_OK)) {
- return njs_function_call(vm, retval, 0);
- }
-
- return ret;
-}
-
-
-nxt_noinline njs_ret_t
njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance)
{
size_t size;
@@ -978,9 +942,9 @@ njs_function_prototype_apply(njs_vm_t *v
njs_ret_t
-njs_function_activate(njs_vm_t *vm, njs_function_t *function, njs_value_t *this,
- const njs_value_t *args, nxt_uint_t nargs, njs_index_t retval,
- size_t advance)
+njs_function_activate(njs_vm_t *vm, njs_function_t *function,
+ const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t retval, size_t advance)
{
njs_ret_t ret;
njs_continuation_t *cont;
diff -r d357ff6b4fe3 -r 7029ec713458 njs/njs_function.h
--- a/njs/njs_function.h Tue Jan 08 06:14:36 2019 +0800
+++ b/njs/njs_function.h Tue Jan 08 06:14:36 2019 +0800
@@ -162,8 +162,6 @@ njs_value_t *njs_function_property_proto
njs_value_t *value);
njs_ret_t njs_function_constructor(njs_vm_t *vm, njs_value_t *args,
nxt_uint_t nargs, njs_index_t unused);
-njs_ret_t njs_function_apply(njs_vm_t *vm, njs_function_t *function,
- njs_value_t *args, nxt_uint_t nargs, njs_index_t retval);
njs_ret_t njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
size_t reserve, nxt_bool_t ctor);
@@ -171,7 +169,7 @@ njs_ret_t njs_function_frame(njs_vm_t *v
const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
nxt_bool_t ctor);
njs_ret_t njs_function_activate(njs_vm_t *vm, njs_function_t *function,
- njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
+ const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
njs_index_t retval, size_t advance);
njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
njs_ret_t njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
@@ -180,6 +178,15 @@ njs_ret_t njs_function_native_call(njs_v
void njs_function_frame_free(njs_vm_t *vm, njs_native_frame_t *frame);
+nxt_inline njs_ret_t
+njs_function_apply(njs_vm_t *vm, njs_function_t *function,
+ const njs_value_t *args, nxt_uint_t nargs, njs_index_t retval)
+{
+ return njs_function_activate(vm, function, &args[0], &args[1], nargs - 1,
+ retval, 0);
+}
+
+
nxt_inline njs_native_frame_t *
njs_function_previous_frame(njs_native_frame_t *frame)
{
From xeioex at nginx.com Thu Jan 10 17:25:02 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Thu, 10 Jan 2019 17:25:02 +0000
Subject: [njs] Introduced njs_function_frame().
Message-ID:
details: https://hg.nginx.org/njs/rev/f62736ecfa8f
branches:
changeset: 724:f62736ecfa8f
user: hongzhidao
date: Tue Jan 08 08:41:40 2019 +0800
description:
Introduced njs_function_frame().
diffstat:
njs/njs_function.h | 15 +++++++++++++++
njs/njs_vm.c | 25 ++++++++++---------------
2 files changed, 25 insertions(+), 15 deletions(-)
diffs (69 lines):
diff -r ecf08b8a7dbe -r f62736ecfa8f njs/njs_function.h
--- a/njs/njs_function.h Tue Jan 08 07:04:24 2019 +0800
+++ b/njs/njs_function.h Tue Jan 08 08:41:40 2019 +0800
@@ -180,6 +180,21 @@ void njs_function_frame_free(njs_vm_t *v
nxt_inline njs_ret_t
+njs_function_frame(njs_vm_t *vm, njs_function_t *function,
+ const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
+ size_t reserve, nxt_bool_t ctor)
+{
+ if (function->native) {
+ return njs_function_native_frame(vm, function, this, args, nargs,
+ reserve, ctor);
+
+ } else {
+ return njs_function_lambda_frame(vm, function, this, args, nargs, ctor);
+ }
+}
+
+
+nxt_inline njs_ret_t
njs_function_apply(njs_vm_t *vm, njs_function_t *function,
const njs_value_t *args, nxt_uint_t nargs, njs_index_t retval)
{
diff -r ecf08b8a7dbe -r f62736ecfa8f njs/njs_vm.c
--- a/njs/njs_vm.c Tue Jan 08 07:04:24 2019 +0800
+++ b/njs/njs_vm.c Tue Jan 08 08:41:40 2019 +0800
@@ -1864,9 +1864,15 @@ njs_function_frame_create(njs_vm_t *vm,
function = value->data.u.function;
- if (!function->native) {
-
- if (ctor) {
+ if (ctor) {
+ if (function->native) {
+ if (!function->ctor) {
+ njs_type_error(vm, "%s is not a constructor",
+ njs_type_string(value->type));
+ return NXT_ERROR;
+ }
+
+ } else {
object = njs_function_new_object(vm, value);
if (nxt_slow_path(object == NULL)) {
return NXT_ERROR;
@@ -1877,20 +1883,9 @@ njs_function_frame_create(njs_vm_t *vm,
val.data.truth = 1;
this = &val;
}
-
- return njs_function_lambda_frame(vm, function, this, NULL,
- nargs, ctor);
}
- if (!ctor || function->ctor) {
- return njs_function_native_frame(vm, function, this, NULL,
- nargs, 0, ctor);
- }
-
- njs_type_error(vm, "%s is not a constructor",
- njs_type_string(value->type));
-
- return NXT_ERROR;
+ return njs_function_frame(vm, function, this, NULL, nargs, 0, ctor);
}
njs_type_error(vm, "%s is not a function", njs_type_string(value->type));
From xeioex at nginx.com Thu Jan 10 17:25:02 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Thu, 10 Jan 2019 17:25:02 +0000
Subject: [njs] Renamed functions related to lambda.
Message-ID:
details: https://hg.nginx.org/njs/rev/ecf08b8a7dbe
branches:
changeset: 723:ecf08b8a7dbe
user: hongzhidao
date: Tue Jan 08 07:04:24 2019 +0800
description:
Renamed functions related to lambda.
diffstat:
njs/njs_function.c | 8 ++++----
njs/njs_function.h | 5 +++--
njs/njs_vm.c | 7 ++++---
3 files changed, 11 insertions(+), 9 deletions(-)
diffs (81 lines):
diff -r 7029ec713458 -r ecf08b8a7dbe njs/njs_function.c
--- a/njs/njs_function.c Tue Jan 08 06:14:36 2019 +0800
+++ b/njs/njs_function.c Tue Jan 08 07:04:24 2019 +0800
@@ -266,7 +266,7 @@ njs_function_native_frame(njs_vm_t *vm,
nxt_noinline njs_ret_t
-njs_function_frame(njs_vm_t *vm, njs_function_t *function,
+njs_function_lambda_frame(njs_vm_t *vm, njs_function_t *function,
const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
nxt_bool_t ctor)
{
@@ -393,7 +393,7 @@ njs_function_frame_alloc(njs_vm_t *vm, s
nxt_noinline njs_ret_t
-njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance)
+njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval, size_t advance)
{
size_t size;
njs_ret_t ret;
@@ -968,13 +968,13 @@ njs_function_activate(njs_vm_t *vm, njs_
return NJS_APPLIED;
}
- ret = njs_function_frame(vm, function, this, args, nargs, 0);
+ ret = njs_function_lambda_frame(vm, function, this, args, nargs, 0);
if (nxt_slow_path(ret != NXT_OK)) {
return ret;
}
- return njs_function_call(vm, retval, advance);
+ return njs_function_lambda_call(vm, retval, advance);
}
diff -r 7029ec713458 -r ecf08b8a7dbe njs/njs_function.h
--- a/njs/njs_function.h Tue Jan 08 06:14:36 2019 +0800
+++ b/njs/njs_function.h Tue Jan 08 07:04:24 2019 +0800
@@ -165,13 +165,14 @@ njs_ret_t njs_function_constructor(njs_v
njs_ret_t njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
size_t reserve, nxt_bool_t ctor);
-njs_ret_t njs_function_frame(njs_vm_t *vm, njs_function_t *function,
+njs_ret_t njs_function_lambda_frame(njs_vm_t *vm, njs_function_t *function,
const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
nxt_bool_t ctor);
njs_ret_t njs_function_activate(njs_vm_t *vm, njs_function_t *function,
const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
njs_index_t retval, size_t advance);
-njs_ret_t njs_function_call(njs_vm_t *vm, njs_index_t retval, size_t advance);
+njs_ret_t njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval,
+ size_t advance);
njs_ret_t njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
njs_value_t *args, uint8_t *args_types, nxt_uint_t nargs,
njs_index_t retval);
diff -r 7029ec713458 -r ecf08b8a7dbe njs/njs_vm.c
--- a/njs/njs_vm.c Tue Jan 08 06:14:36 2019 +0800
+++ b/njs/njs_vm.c Tue Jan 08 07:04:24 2019 +0800
@@ -1878,7 +1878,8 @@ njs_function_frame_create(njs_vm_t *vm,
this = &val;
}
- return njs_function_frame(vm, function, this, NULL, nargs, ctor);
+ return njs_function_lambda_frame(vm, function, this, NULL,
+ nargs, ctor);
}
if (!ctor || function->ctor) {
@@ -2029,8 +2030,8 @@ njs_vmcode_function_call(njs_vm_t *vm, n
function = frame->function;
if (!function->native) {
- ret = njs_function_call(vm, (njs_index_t) retval,
- sizeof(njs_vmcode_function_call_t));
+ ret = njs_function_lambda_call(vm, (njs_index_t) retval,
+ sizeof(njs_vmcode_function_call_t));
if (nxt_fast_path(ret != NJS_ERROR)) {
return 0;
From xeioex at nginx.com Thu Jan 10 17:25:02 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Thu, 10 Jan 2019 17:25:02 +0000
Subject: [njs] Making njs_function_frame_alloc() static.
Message-ID:
details: https://hg.nginx.org/njs/rev/112bd230858c
branches:
changeset: 725:112bd230858c
user: Dmitry Volyntsev
date: Thu Jan 10 20:18:27 2019 +0300
description:
Making njs_function_frame_alloc() static.
diffstat:
njs/njs_function.c | 1 +
njs/njs_function.h | 1 -
2 files changed, 1 insertions(+), 1 deletions(-)
diffs (22 lines):
diff -r f62736ecfa8f -r 112bd230858c njs/njs_function.c
--- a/njs/njs_function.c Tue Jan 08 08:41:40 2019 +0800
+++ b/njs/njs_function.c Thu Jan 10 20:18:27 2019 +0300
@@ -8,6 +8,7 @@
#include
+static njs_native_frame_t *njs_function_frame_alloc(njs_vm_t *vm, size_t size);
static njs_ret_t njs_normalize_args(njs_vm_t *vm, njs_value_t *args,
uint8_t *args_types, nxt_uint_t nargs);
diff -r f62736ecfa8f -r 112bd230858c njs/njs_function.h
--- a/njs/njs_function.h Tue Jan 08 08:41:40 2019 +0800
+++ b/njs/njs_function.h Thu Jan 10 20:18:27 2019 +0300
@@ -149,7 +149,6 @@ struct njs_frame_s {
njs_function_t *njs_function_alloc(njs_vm_t *vm);
njs_function_t *njs_function_value_copy(njs_vm_t *vm, njs_value_t *value);
-njs_native_frame_t *njs_function_frame_alloc(njs_vm_t *vm, size_t size);
njs_ret_t njs_function_arguments_object_init(njs_vm_t *vm,
njs_native_frame_t *frame);
njs_ret_t njs_function_rest_parameters_init(njs_vm_t *vm,
From xeioex at nginx.com Fri Jan 11 16:20:29 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Fri, 11 Jan 2019 16:20:29 +0000
Subject: [njs] Improved an argument name of njs_function_frame().
Message-ID:
details: https://hg.nginx.org/njs/rev/fb2c2bca61c2
branches:
changeset: 727:fb2c2bca61c2
user: hongzhidao
date: Fri Jan 11 19:20:38 2019 +0800
description:
Improved an argument name of njs_function_frame().
diffstat:
njs/njs_function.c | 8 ++++----
njs/njs_function.h | 6 +++---
2 files changed, 7 insertions(+), 7 deletions(-)
diffs (58 lines):
diff -r 8fb687d866de -r fb2c2bca61c2 njs/njs_function.c
--- a/njs/njs_function.c Fri Jan 11 18:57:57 2019 +0800
+++ b/njs/njs_function.c Fri Jan 11 19:20:38 2019 +0800
@@ -216,16 +216,16 @@ njs_function_arguments_thrower(njs_vm_t
njs_ret_t
njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- size_t reserve, nxt_bool_t ctor)
+ size_t continuation_size, nxt_bool_t ctor)
{
size_t size;
nxt_uint_t n;
njs_value_t *value, *bound;
njs_native_frame_t *frame;
- reserve = nxt_max(reserve, function->continuation_size);
+ continuation_size = nxt_max(continuation_size, function->continuation_size);
- size = NJS_NATIVE_FRAME_SIZE + reserve
+ size = NJS_NATIVE_FRAME_SIZE + continuation_size
+ (function->args_offset + nargs) * sizeof(njs_value_t);
frame = njs_function_frame_alloc(vm, size);
@@ -237,7 +237,7 @@ njs_function_native_frame(njs_vm_t *vm,
frame->nargs = function->args_offset + nargs;
frame->ctor = ctor;
- value = (njs_value_t *) (njs_continuation(frame) + reserve);
+ value = (njs_value_t *) (njs_continuation(frame) + continuation_size);
frame->arguments = value;
bound = function->bound;
diff -r 8fb687d866de -r fb2c2bca61c2 njs/njs_function.h
--- a/njs/njs_function.h Fri Jan 11 18:57:57 2019 +0800
+++ b/njs/njs_function.h Fri Jan 11 19:20:38 2019 +0800
@@ -163,7 +163,7 @@ njs_ret_t njs_function_constructor(njs_v
nxt_uint_t nargs, njs_index_t unused);
njs_ret_t njs_function_native_frame(njs_vm_t *vm, njs_function_t *function,
const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- size_t reserve, nxt_bool_t ctor);
+ size_t continuation_size, nxt_bool_t ctor);
njs_ret_t njs_function_lambda_frame(njs_vm_t *vm, njs_function_t *function,
const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
nxt_bool_t ctor);
@@ -181,11 +181,11 @@ void njs_function_frame_free(njs_vm_t *v
nxt_inline njs_ret_t
njs_function_frame(njs_vm_t *vm, njs_function_t *function,
const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
- size_t reserve, nxt_bool_t ctor)
+ size_t continuation_size, nxt_bool_t ctor)
{
if (function->native) {
return njs_function_native_frame(vm, function, this, args, nargs,
- reserve, ctor);
+ continuation_size, ctor);
} else {
return njs_function_lambda_frame(vm, function, this, args, nargs, ctor);
From xeioex at nginx.com Fri Jan 11 16:20:28 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Fri, 11 Jan 2019 16:20:28 +0000
Subject: [njs] Refactored njs_function_lambda_call().
Message-ID:
details: https://hg.nginx.org/njs/rev/8fb687d866de
branches:
changeset: 726:8fb687d866de
user: hongzhidao
date: Fri Jan 11 18:57:57 2019 +0800
description:
Refactored njs_function_lambda_call().
diffstat:
njs/njs_function.c | 35 +++++++++++++++++----------------
njs/njs_function.h | 2 +-
njs/njs_vm.c | 55 ++++++++++++++++++++++++-----------------------------
3 files changed, 44 insertions(+), 48 deletions(-)
diffs (163 lines):
diff -r 112bd230858c -r 8fb687d866de njs/njs_function.c
--- a/njs/njs_function.c Thu Jan 10 20:18:27 2019 +0300
+++ b/njs/njs_function.c Fri Jan 11 18:57:57 2019 +0800
@@ -394,7 +394,8 @@ njs_function_frame_alloc(njs_vm_t *vm, s
nxt_noinline njs_ret_t
-njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval, size_t advance)
+njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval,
+ u_char *return_address)
{
size_t size;
njs_ret_t ret;
@@ -408,9 +409,9 @@ njs_function_lambda_call(njs_vm_t *vm, n
frame = (njs_frame_t *) vm->top_frame;
frame->retval = retval;
+ frame->return_address = return_address;
function = frame->native.function;
- frame->return_address = vm->current + advance;
lambda = function->u.lambda;
vm->current = lambda->start;
@@ -947,35 +948,35 @@ njs_function_activate(njs_vm_t *vm, njs_
const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
njs_index_t retval, size_t advance)
{
+ u_char *return_address;
njs_ret_t ret;
njs_continuation_t *cont;
+ ret = njs_function_frame(vm, function, this, args, nargs,
+ NJS_CONTINUATION_SIZE, 0);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+
+ return_address = vm->current + advance;
+
if (function->native) {
- ret = njs_function_native_frame(vm, function, this, args, nargs,
- NJS_CONTINUATION_SIZE, 0);
- if (nxt_slow_path(ret != NXT_OK)) {
- return ret;
- }
-
cont = njs_vm_continuation(vm);
cont->function = function->u.native;
cont->args_types = function->args_types;
cont->retval = retval;
+ cont->return_address = return_address;
- cont->return_address = vm->current + advance;
vm->current = (u_char *) njs_continuation_nexus;
- return NJS_APPLIED;
+ ret = NJS_APPLIED;
+
+ } else {
+ ret = njs_function_lambda_call(vm, retval, return_address);
}
- ret = njs_function_lambda_frame(vm, function, this, args, nargs, 0);
-
- if (nxt_slow_path(ret != NXT_OK)) {
- return ret;
- }
-
- return njs_function_lambda_call(vm, retval, advance);
+ return ret;
}
diff -r 112bd230858c -r 8fb687d866de njs/njs_function.h
--- a/njs/njs_function.h Thu Jan 10 20:18:27 2019 +0300
+++ b/njs/njs_function.h Fri Jan 11 18:57:57 2019 +0800
@@ -171,7 +171,7 @@ njs_ret_t njs_function_activate(njs_vm_t
const njs_value_t *this, const njs_value_t *args, nxt_uint_t nargs,
njs_index_t retval, size_t advance);
njs_ret_t njs_function_lambda_call(njs_vm_t *vm, njs_index_t retval,
- size_t advance);
+ u_char *return_address);
njs_ret_t njs_function_native_call(njs_vm_t *vm, njs_function_native_t native,
njs_value_t *args, uint8_t *args_types, nxt_uint_t nargs,
njs_index_t retval);
diff -r 112bd230858c -r 8fb687d866de njs/njs_vm.c
--- a/njs/njs_vm.c Thu Jan 10 20:18:27 2019 +0300
+++ b/njs/njs_vm.c Fri Jan 11 18:57:57 2019 +0800
@@ -2014,9 +2014,8 @@ njs_vmcode_method_frame(njs_vm_t *vm, nj
njs_ret_t
njs_vmcode_function_call(njs_vm_t *vm, njs_value_t *invld, njs_value_t *retval)
{
+ u_char *return_address;
njs_ret_t ret;
- nxt_uint_t nargs;
- njs_value_t *args;
njs_function_t *function;
njs_continuation_t *cont;
njs_native_frame_t *frame;
@@ -2024,37 +2023,33 @@ njs_vmcode_function_call(njs_vm_t *vm, n
frame = vm->top_frame;
function = frame->function;
- if (!function->native) {
+ return_address = vm->current + sizeof(njs_vmcode_function_call_t);
+
+ if (function->native) {
+ if (function->continuation_size != 0) {
+ cont = njs_vm_continuation(vm);
+
+ cont->function = function->u.native;
+ cont->args_types = function->args_types;
+ cont->retval = (njs_index_t) retval;
+ cont->return_address = return_address;
+
+ vm->current = (u_char *) njs_continuation_nexus;
+
+ ret = NJS_APPLIED;
+
+ } else {
+ ret = njs_function_native_call(vm, function->u.native,
+ frame->arguments,
+ function->args_types, frame->nargs,
+ (njs_index_t) retval);
+ }
+
+ } else {
ret = njs_function_lambda_call(vm, (njs_index_t) retval,
- sizeof(njs_vmcode_function_call_t));
-
- if (nxt_fast_path(ret != NJS_ERROR)) {
- return 0;
- }
-
- return ret;
+ return_address);
}
- args = frame->arguments;
- nargs = frame->nargs;
-
- if (function->continuation_size != 0) {
- cont = njs_vm_continuation(vm);
-
- cont->function = function->u.native;
- cont->args_types = function->args_types;
- cont->retval = (njs_index_t) retval;
-
- cont->return_address = vm->current + sizeof(njs_vmcode_function_call_t);
- vm->current = (u_char *) njs_continuation_nexus;
-
- return 0;
- }
-
- ret = njs_function_native_call(vm, function->u.native, args,
- function->args_types, nargs,
- (njs_index_t) retval);
-
switch (ret) {
case NXT_OK:
return sizeof(njs_vmcode_function_call_t);
From msellers at ranchmed.com Mon Jan 14 16:33:23 2019
From: msellers at ranchmed.com (Mark Sellers)
Date: Mon, 14 Jan 2019 08:33:23 -0800
Subject: Interaction between ngx module and fastcgi program
Message-ID: <9484113F-2F71-49F6-BAA1-3F3A8E8F77AF@ranchmed.com>
Thanks for your great feedback. It is truly appreciated.
I am finalizing a simple nginx module, that does a uri rewrite. I have tested it, and the rewrite is working fine for files that exist on the server.
A second component of my system is a fastcgi program (written in C) that, upon execution using the try_files named location. This fastcgi program has been tested, and works fine, by itself.
My problem comes when both the module and fastcgi program are working together. Something in the combined environment is causing a malfunction.
Could you please take a look at the annotated debug outputs, and suggest an approach to find the issue, and fix it? Please refer to below and see my notes offset to the left of the listing:
Debug log with module and fastcgi both operating (I removed the first two columns of the debut output to provide a better fit on this page:
[debug] 20594#0: *1 event timer del: 19: 556031347
[debug] 20594#0: *1 rewrite phase: 0
[debug] 20594#0: *1 test location: "/"
[debug] 20594#0: *1 test location: "images/"
[debug] 20594#0: *1 using configuration "/images/"
[debug] 20594#0: *1 http cl:-1 max:104857600
[debug] 20594#0: *1 rewrite phase: 2
[debug] 20594#0: *1 fastimg handler <- My module
[debug] 20594#0: *1 ngx_http_fastimg_rewrite() uri in: "/images/12/255/0/0.jpg? <- Input uri
[debug] 20594#0: *1 ngx_http_fastimg_rewrite() uri out: "/images/21/12_255_0_0.jpg? <- Output uri (rewritten)
[debug] 20594#0: *1 internal redirect: "/images/21/12_255_0_0.jpg?? <- Internal redirect using ngx_http_internal_redirect(r, &uri, NULL)
[debug] 20594#0: *1 rewrite phase: 0
[debug] 20594#0: *1 test location: "/"
[debug] 20594#0: *1 test location: "images/"
[debug] 20594#0: *1 using configuration "/images/? <- Config location is ?/images/"
[debug] 20594#0: *1 http cl:-1 max:104857600
[debug] 20594#0: *1 rewrite phase: 2
[debug] 20594#0: *1 fastimg handler
[debug] 20594#0: *1 rewrite phase: 3
[debug] 20594#0: *1 post rewrite phase: 4
[debug] 20594#0: *1 generic phase: 5
[debug] 20594#0: *1 generic phase: 6
[debug] 20594#0: *1 access phase: 7
[debug] 20594#0: *1 access phase: 8
[debug] 20594#0: *1 post access phase: 9
[debug] 20594#0: *1 generic phase: 10
[debug] 20594#0: *1 try files handler <- Try files can?t find the image in the filesystem
[debug] 20594#0: *1 http script var: "/images/21/12_255_0_0.jpg"
[debug] 20594#0: *1 trying to use file: "/images/21/12_255_0_0.jpg" "/var/www/html/static.ranchmed.com/images/21/12_255_0_0.jpg"
[debug] 20594#0: *1 trying to use file: "@fastimg_fcgi" "/var/www/html/static.ranchmed.com at fastimg_fcgi"
[debug] 20594#0: *1 test location: "@fastimg_fcgi"
[debug] 20594#0: *1 using location: @fastimg_fcgi "/images/21/12_255_0_0.jpg?? <- And executes my fastimg_fcgi program
[debug] 20594#0: *1 rewrite phase: 2
[debug] 20594#0: *1 rewrite phase: 3
[debug] 20594#0: *1 post rewrite phase: 4
[debug] 20594#0: *1 generic phase: 5
[debug] 20594#0: *1 generic phase: 6
[debug] 20594#0: *1 access phase: 7
[debug] 20594#0: *1 access phase: 8
[debug] 20594#0: *1 post access phase: 9
[debug] 20594#0: *1 generic phase: 10
[debug] 20594#0: *1 generic phase: 11
[debug] 20594#0: *1 http init upstream, client timer: 0
[debug] 20594#0: *1 epoll add event: fd:19 op:3 ev:80002005
[debug] 20594#0: *1 http script copy: ?QUERY_STRING? <- Preparing environment variables for fcgi access
[debug] 20594#0: *1 fastcgi param: "QUERY_STRING: "
[debug] 20594#0: *1 http script copy: "REQUEST_METHOD"
[debug] 20594#0: *1 http script var: "GET"
[debug] 20594#0: *1 fastcgi param: "REQUEST_METHOD: GET"
[debug] 20594#0: *1 http script copy: "CONTENT_TYPE"
[debug] 20594#0: *1 fastcgi param: "CONTENT_TYPE: "
[debug] 20594#0: *1 http script copy: "CONTENT_LENGTH"
[debug] 20594#0: *1 fastcgi param: "CONTENT_LENGTH: "
[debug] 20594#0: *1 http script copy: "SCRIPT_NAME"
[debug] 20594#0: *1 http script var: "/images/21/12_255_0_0.jpg"
[debug] 20594#0: *1 fastcgi param: "SCRIPT_NAME: /images/21/12_255_0_0.jpg? <- Is this a problem? This is a C fcgi program, and I didn?t set SCRIPT_NAME
[debug] 20594#0: *1 http script copy: "REQUEST_URI"
[debug] 20594#0: *1 http script var: "/images/12/255/0/0.jpg"
[debug] 20594#0: *1 fastcgi param: "REQUEST_URI: /images/12/255/0/0.jpg? <- Request URI - I don?t use this, because it is the original
[debug] 20594#0: *1 http script copy: "DOCUMENT_URI"
[debug] 20594#0: *1 http script var: "/images/21/12_255_0_0.jpg"
[debug] 20594#0: *1 fastcgi param: "DOCUMENT_URI: /images/21/12_255_0_0.jpg? <- fcgi program uses this URI
[debug] 20594#0: *1 http script copy: "DOCUMENT_ROOT"
[debug] 20594#0: *1 http script var: "/var/www/html/static.ranchmed.com"
[debug] 20594#0: *1 fastcgi param: "DOCUMENT_ROOT: /var/www/html/static.ranchmed.com"
[debug] 20594#0: *1 http script copy: "SERVER_PROTOCOL"
[debug] 20594#0: *1 http script var: "HTTP/1.0"
[debug] 20594#0: *1 fastcgi param: "SERVER_PROTOCOL: HTTP/1.0"
[debug] 20594#0: *1 http script copy: "REQUEST_SCHEME"
[debug] 20594#0: *1 http script var: "http"
[debug] 20594#0: *1 fastcgi param: "REQUEST_SCHEME: http"
[debug] 20594#0: *1 http script copy: ""
[debug] 20594#0: *1 http script copy: "GATEWAY_INTERFACE"
[debug] 20594#0: *1 http script copy: "CGI/1.1"
[debug] 20594#0: *1 fastcgi param: "GATEWAY_INTERFACE: CGI/1.1"
[debug] 20594#0: *1 http script copy: "SERVER_SOFTWARE"
[debug] 20594#0: *1 http script copy: "nginx/"
[debug] 20594#0: *1 http script var: "1.15.7"
[debug] 20594#0: *1 fastcgi param: "SERVER_SOFTWARE: nginx/1.15.7"
[debug] 20594#0: *1 http script copy: "REMOTE_ADDR"
[debug] 20594#0: *1 http script var: "96.236.66.50"
[debug] 20594#0: *1 fastcgi param: "REMOTE_ADDR: 96.236.66.50"
[debug] 20594#0: *1 http script copy: "REMOTE_PORT"
[debug] 20594#0: *1 http script var: "50046"
[debug] 20594#0: *1 fastcgi param: "REMOTE_PORT: 50046"
[debug] 20594#0: *1 http script copy: "SERVER_ADDR"
[debug] 20594#0: *1 http script var: "192.168.1.101"
[debug] 20594#0: *1 fastcgi param: "SERVER_ADDR: 192.168.1.101"
[debug] 20594#0: *1 http script copy: "SERVER_PORT"
[debug] 20594#0: *1 http script var: "80"
[debug] 20594#0: *1 fastcgi param: "SERVER_PORT: 80"
[debug] 20594#0: *1 http script copy: "SERVER_NAME"
[debug] 20594#0: *1 http script var: "static.ranchmed.com"
[debug] 20594#0: *1 fastcgi param: "SERVER_NAME: static.ranchmed.com"
[debug] 20594#0: *1 fastcgi param: "HTTP_HOST: static.ranchmed.com"
[debug] 20594#0: *1 fastcgi param: "HTTP_X_REAL_IP: 96.236.66.50"
[debug] 20594#0: *1 fastcgi param: "HTTP_X_FORWARDED_FOR: 96.236.66.50"
[debug] 20594#0: *1 fastcgi param: "HTTP_CONNECTION: close"
[debug] 20594#0: *1 fastcgi param: "HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:65.0) Gecko/20100101 Firefox/65.0"
[debug] 20594#0: *1 fastcgi param: "HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
[debug] 20594#0: *1 fastcgi param: "HTTP_ACCEPT_LANGUAGE: en-US,en;q=0.5"
[debug] 20594#0: *1 fastcgi param: "HTTP_ACCEPT_ENCODING: gzip, deflate, br"
[debug] 20594#0: *1 fastcgi param: "HTTP_UPGRADE_INSECURE_REQUESTS: 1"
[debug] 20594#0: *1 fastcgi param: "HTTP_CACHE_CONTROL: max-age=0"
[debug] 20594#0: *1 http cleanup add: 0000000000D32CD8
[debug] 20594#0: *1 get rr peer, try: 1
[debug] 20594#0: *1 stream socket 20
[debug] 20594#0: *1 epoll add connection: fd:20 ev:80002005
[debug] 20594#0: *1 connect to 127.0.0.1:9000, fd:20 #2
[debug] 20594#0: *1 http upstream connect: -2
[debug] 20594#0: *1 posix_memalign: 0000000000D14A50:128 @16
[debug] 20594#0: *1 event timer add: 20: 60000:556031347
[debug] 20594#0: *1 http finalize request: -4, "/images/21/12_255_0_0.jpg?" a:1, c:4
[debug] 20594#0: *1 http request count:4 blk:0
[debug] 20594#0: *1 http finalize request: -4, "/images/21/12_255_0_0.jpg?" a:1, c:3
[debug] 20594#0: *1 http request count:3 blk:0
[debug] 20594#0: timer delta: 0
[debug] 20594#0: worker cycle
[debug] 20594#0: epoll timer: 60000
[debug] 20594#0: epoll: fd:19 ev:0004 d:0000000000D4E4D0
[debug] 20594#0: *1 http run request: "/images/21/12_255_0_0.jpg?"
[debug] 20594#0: *1 http upstream check client, write event:1, "/images/21/12_255_0_0.jpg"
[debug] 20594#0: epoll: fd:20 ev:0004 d:0000000000D4E5B8
[debug] 20594#0: *1 http upstream request: "/images/21/12_255_0_0.jpg?"
[debug] 20594#0: *1 http upstream send request handler
[debug] 20594#0: *1 http upstream send request
[debug] 20594#0: *1 http upstream send request body
[debug] 20594#0: *1 chain writer buf fl:0 s:920
[debug] 20594#0: *1 chain writer in: 0000000000D32D18
[debug] 20594#0: *1 writev: 920 of 920
[debug] 20594#0: *1 chain writer out: 0000000000000000
[debug] 20594#0: *1 event timer del: 20: 556031347
[debug] 20594#0: *1 event timer add: 20: 60000:556031348
[debug] 20594#0: timer delta: 1
[debug] 20594#0: worker cycle
[debug] 20594#0: epoll timer: 60000
[debug] 20594#0: epoll: fd:20 ev:0005 d:0000000000D4E5B8
[debug] 20594#0: *1 http upstream request: "0100101 Firefox/?D <- SOMETHING IS BROKE!!
?"
[debug] 20594#0: *1 http upstream process header
[debug] 20594#0: *1 malloc: 0000000000D24EB0:4096
[debug] 20594#0: *1 recv: eof:0, avail:1
[debug] 20594#0: *1 recv: fd:20 4096 of 4096
[debug] 20594#0: *1 http fastcgi record byte: 01
[debug] 20594#0: *1 http fastcgi record byte: 06
[debug] 20594#0: *1 http fastcgi record byte: 00
[debug] 20594#0: *1 http fastcgi record byte: 01
[debug] 20594#0: *1 http fastcgi record byte: 1F
[debug] 20594#0: *1 http fastcgi record byte: F8
[debug] 20594#0: *1 http fastcgi record byte: 00
[debug] 20594#0: *1 http fastcgi record byte: 00
[debug] 20594#0: *1 http fastcgi record length: 8184
[debug] 20594#0: *1 http fastcgi parser: 0
[debug] 20594#0: *1 http fastcgi header: "Content-type: image/jpeg"
[debug] 20594#0: *1 http fastcgi parser: 1
[debug] 20594#0: *1 http fastcgi header done
[debug] 20594#0: *1 posix_memalign: 0000000000D18E70:4096 @16
[debug] 20594#0: *1 HTTP/1.1 200 OK
Server: nginx/1.15.7
Date: Sun, 13 Jan 2019 15:37:24 GMT
Content-Type: image/jpeg
Connection: close
You may suspect that the fcgi program is crashing. I tested this by turning off the module, and executing the fcgi program by manually specifying the ?rewritten? uri. Here is the output of a successful completion for the fcgi program:
[debug] 20730#0: *1 event timer del: 12: 557645604
[debug] 20730#0: *1 rewrite phase: 0
[debug] 20730#0: *1 test location: "/"
[debug] 20730#0: *1 test location: "images/"
[debug] 20730#0: *1 using configuration "/images/"
[debug] 20730#0: *1 http cl:-1 max:104857600
[debug] 20730#0: *1 rewrite phase: 2
[debug] 20730#0: *1 rewrite phase: 3
[debug] 20730#0: *1 post rewrite phase: 4 <- No rewrite - my module is disabled
[debug] 20730#0: *1 generic phase: 5
[debug] 20730#0: *1 generic phase: 6
[debug] 20730#0: *1 access phase: 7
[debug] 20730#0: *1 access phase: 8
[debug] 20730#0: *1 post access phase: 9
[debug] 20730#0: *1 generic phase: 10
[debug] 20730#0: *1 try files handler <- Try files can?t find the image in the filesystem
[debug] 20730#0: *1 http script var: "/images/21/12_260_0_0.jpg"
[debug] 20730#0: *1 trying to use file: "/images/21/12_260_0_0.jpg" "/var/www/html/static.ranchmed.com/images/21/12_260_0_0.jpg"
[debug] 20730#0: *1 trying to use file: "@fastimg_fcgi" "/var/www/html/static.ranchmed.com at fastimg_fcgi"
[debug] 20730#0: *1 test location: "@fastimg_fcgi"
[debug] 20730#0: *1 using location: @fastimg_fcgi "/images/21/12_260_0_0.jpg?? <- And executes my fastimg_fcgi program
[debug] 20730#0: *1 rewrite phase: 2
[debug] 20730#0: *1 rewrite phase: 3
[debug] 20730#0: *1 post rewrite phase: 4
[debug] 20730#0: *1 generic phase: 5
[debug] 20730#0: *1 generic phase: 6
[debug] 20730#0: *1 access phase: 7
[debug] 20730#0: *1 access phase: 8
[debug] 20730#0: *1 post access phase: 9
[debug] 20730#0: *1 generic phase: 10
[debug] 20730#0: *1 generic phase: 11
[debug] 20730#0: *1 http init upstream, client timer: 0
[debug] 20730#0: *1 epoll add event: fd:12 op:3 ev:80002005
[debug] 20730#0: *1 http script copy: "QUERY_STRING"
[debug] 20730#0: *1 fastcgi param: "QUERY_STRING: "
[debug] 20730#0: *1 http script copy: "REQUEST_METHOD"
[debug] 20730#0: *1 http script var: "GET"
[debug] 20730#0: *1 fastcgi param: "REQUEST_METHOD: GET"
[debug] 20730#0: *1 http script copy: "CONTENT_TYPE"
[debug] 20730#0: *1 fastcgi param: "CONTENT_TYPE: "
[debug] 20730#0: *1 http script copy: "CONTENT_LENGTH"
[debug] 20730#0: *1 fastcgi param: "CONTENT_LENGTH: "
[debug] 20730#0: *1 http script copy: "SCRIPT_NAME"
[debug] 20730#0: *1 http script var: "/images/21/12_260_0_0.jpg"
[debug] 20730#0: *1 fastcgi param: "SCRIPT_NAME: /images/21/12_260_0_0.jpg"
[debug] 20730#0: *1 http script copy: "REQUEST_URI"
[debug] 20730#0: *1 http script var: "/images/21/12_260_0_0.jpg"
[debug] 20730#0: *1 fastcgi param: "REQUEST_URI: /images/21/12_260_0_0.jpg? <- Spoofed the URI (manually set the redirect uri)
[debug] 20730#0: *1 http script copy: "DOCUMENT_URI"
[debug] 20730#0: *1 http script var: "/images/21/12_260_0_0.jpg? <- This var is used in the fcgi
[debug] 20730#0: *1 fastcgi param: "DOCUMENT_URI: /images/21/12_260_0_0.jpg"
[debug] 20730#0: *1 http script copy: "DOCUMENT_ROOT"
[debug] 20730#0: *1 http script var: "/var/www/html/static.ranchmed.com"
[debug] 20730#0: *1 fastcgi param: "DOCUMENT_ROOT: /var/www/html/static.ranchmed.com"
[debug] 20730#0: *1 http script copy: "SERVER_PROTOCOL"
[debug] 20730#0: *1 http script var: "HTTP/1.0"
[debug] 20730#0: *1 fastcgi param: "SERVER_PROTOCOL: HTTP/1.0"
[debug] 20730#0: *1 http script copy: "REQUEST_SCHEME"
[debug] 20730#0: *1 http script var: "http"
[debug] 20730#0: *1 fastcgi param: "REQUEST_SCHEME: http"
[debug] 20730#0: *1 http script copy: ""
[debug] 20730#0: *1 http script copy: "GATEWAY_INTERFACE"
[debug] 20730#0: *1 http script copy: "CGI/1.1"
[debug] 20730#0: *1 fastcgi param: "GATEWAY_INTERFACE: CGI/1.1"
[debug] 20730#0: *1 http script copy: "SERVER_SOFTWARE"
[debug] 20730#0: *1 http script copy: "nginx/"
[debug] 20730#0: *1 http script var: "1.15.7"
[debug] 20730#0: *1 fastcgi param: "SERVER_SOFTWARE: nginx/1.15.7"
[debug] 20730#0: *1 http script copy: "REMOTE_ADDR"
[debug] 20730#0: *1 http script var: "96.236.66.50"
[debug] 20730#0: *1 fastcgi param: "REMOTE_ADDR: 96.236.66.50"
[debug] 20730#0: *1 http script copy: "REMOTE_PORT"
[debug] 20730#0: *1 http script var: "50108"
[debug] 20730#0: *1 fastcgi param: "REMOTE_PORT: 50108"
[debug] 20730#0: *1 http script copy: "SERVER_ADDR"
[debug] 20730#0: *1 http script var: "192.168.1.101"
[debug] 20730#0: *1 fastcgi param: "SERVER_ADDR: 192.168.1.101"
[debug] 20730#0: *1 http script copy: "SERVER_PORT"
[debug] 20730#0: *1 http script var: "80"
[debug] 20730#0: *1 fastcgi param: "SERVER_PORT: 80"
[debug] 20730#0: *1 http script copy: "SERVER_NAME"
[debug] 20730#0: *1 http script var: "static.ranchmed.com"
[debug] 20730#0: *1 fastcgi param: "SERVER_NAME: static.ranchmed.com"
[debug] 20730#0: *1 fastcgi param: "HTTP_HOST: static.ranchmed.com"
[debug] 20730#0: *1 fastcgi param: "HTTP_X_REAL_IP: 96.236.66.50"
[debug] 20730#0: *1 fastcgi param: "HTTP_X_FORWARDED_FOR: 96.236.66.50"
[debug] 20730#0: *1 fastcgi param: "HTTP_CONNECTION: close"
[debug] 20730#0: *1 fastcgi param: "HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:65.0) Gecko/20100101 Firefox/65.0"
[debug] 20730#0: *1 fastcgi param: "HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
[debug] 20730#0: *1 fastcgi param: "HTTP_ACCEPT_LANGUAGE: en-US,en;q=0.5"
[debug] 20730#0: *1 fastcgi param: "HTTP_ACCEPT_ENCODING: gzip, deflate, br"
[debug] 20730#0: *1 fastcgi param: "HTTP_UPGRADE_INSECURE_REQUESTS: 1"
[debug] 20730#0: *1 http cleanup add: 0000000000C0ECC0
[debug] 20730#0: *1 get rr peer, try: 1
[debug] 20730#0: *1 stream socket 14
[debug] 20730#0: *1 epoll add connection: fd:14 ev:80002005
[debug] 20730#0: *1 connect to 127.0.0.1:9000, fd:14 #2
[debug] 20730#0: *1 http upstream connect: -2
[debug] 20730#0: *1 posix_memalign: 0000000000BF0A50:128 @16
[debug] 20730#0: *1 event timer add: 14: 60000:557645604
[debug] 20730#0: *1 http finalize request: -4, "/images/21/12_260_0_0.jpg?" a:1, c:3
[debug] 20730#0: *1 http request count:3 blk:0
[debug] 20730#0: *1 http finalize request: -4, "/images/21/12_260_0_0.jpg?" a:1, c:2
[debug] 20730#0: *1 http request count:2 blk:0
[debug] 20730#0: timer delta: 0
[debug] 20730#0: worker cycle
[debug] 20730#0: epoll timer: 60000
[debug] 20730#0: epoll: fd:12 ev:0004 d:0000000000C2A4D0
[debug] 20730#0: *1 http run request: "/images/21/12_260_0_0.jpg?"
[debug] 20730#0: *1 http upstream check client, write event:1, "/images/21/12_260_0_0.jpg"
[debug] 20730#0: epoll: fd:14 ev:0004 d:0000000000C2A5B8
[debug] 20730#0: *1 http upstream request: "/images/21/12_260_0_0.jpg?"
[debug] 20730#0: *1 http upstream send request handler
[debug] 20730#0: *1 http upstream send request
[debug] 20730#0: *1 http upstream send request body
[debug] 20730#0: *1 chain writer buf fl:0 s:896
[debug] 20730#0: *1 chain writer in: 0000000000C0BB30
[debug] 20730#0: *1 writev: 896 of 896
[debug] 20730#0: *1 chain writer out: 0000000000000000
[debug] 20730#0: *1 event timer del: 14: 557645604
[debug] 20730#0: *1 event timer add: 14: 60000:557645604
[debug] 20730#0: timer delta: 0
[debug] 20730#0: worker cycle
[debug] 20730#0: epoll timer: 60000
[debug] 20730#0: epoll: fd:14 ev:0005 d:0000000000C2A5B8
[debug] 20730#0: *1 http upstream request: "/images/21/12_260_0_0.jpg?"
[debug] 20730#0: *1 http upstream process header
[debug] 20730#0: *1 malloc: 0000000000C00EB0:4096
[debug] 20730#0: *1 recv: eof:0, avail:1
[debug] 20730#0: *1 recv: fd:14 4096 of 4096
[debug] 20730#0: *1 http fastcgi record byte: 01
[debug] 20730#0: *1 http fastcgi record byte: 06
[debug] 20730#0: *1 http fastcgi record byte: 00
[debug] 20730#0: *1 http fastcgi record byte: 01
[debug] 20730#0: *1 http fastcgi record byte: 1F
[debug] 20730#0: *1 http fastcgi record byte: F8
[debug] 20730#0: *1 http fastcgi record byte: 00
[debug] 20730#0: *1 http fastcgi record byte: 00
[debug] 20730#0: *1 http fastcgi record length: 8184
[debug] 20730#0: *1 http fastcgi parser: 0
[debug] 20730#0: *1 http fastcgi header: "Content-type: image/jpeg"
[debug] 20730#0: *1 http fastcgi parser: 1
[debug] 20730#0: *1 http fastcgi header done
[debug] 20730#0: *1 posix_memalign: 0000000000BF4E70:4096 @16
[debug] 20730#0: *1 HTTP/1.1 200 OK <- SUCCESS!!
Server: nginx/1.15.7
Date: Sun, 13 Jan 2019 16:04:18 GMT
Content-Type: image/jpeg
Connection: close
I hope you are able to take a little time to review these two debug listings, and to provide some guidance to understand an approach that I can take to fix the problems!
Many Thanks,
Mark
From mdounin at mdounin.ru Mon Jan 14 16:47:55 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Mon, 14 Jan 2019 19:47:55 +0300
Subject: Interaction between ngx module and fastcgi program
In-Reply-To: <9484113F-2F71-49F6-BAA1-3F3A8E8F77AF@ranchmed.com>
References: <9484113F-2F71-49F6-BAA1-3F3A8E8F77AF@ranchmed.com>
Message-ID: <20190114164755.GE99070@mdounin.ru>
Hello!
On Mon, Jan 14, 2019 at 08:33:23AM -0800, Mark Sellers wrote:
> Thanks for your great feedback. It is truly appreciated.
>
> I am finalizing a simple nginx module, that does a uri rewrite. I have tested it, and the rewrite is working fine for files that exist on the server.
>
> A second component of my system is a fastcgi program (written in C) that, upon execution using the try_files named location. This fastcgi program has been tested, and works fine, by itself.
>
> My problem comes when both the module and fastcgi program are working together. Something in the combined environment is causing a malfunction.
>
> Could you please take a look at the annotated debug outputs, and suggest an approach to find the issue, and fix it? Please refer to below and see my notes offset to the left of the listing:
>
> Debug log with module and fastcgi both operating (I removed the first two columns of the debut output to provide a better fit on this page:
>
>
>
> [debug] 20594#0: *1 event timer del: 19: 556031347
> [debug] 20594#0: *1 rewrite phase: 0
> [debug] 20594#0: *1 test location: "/"
> [debug] 20594#0: *1 test location: "images/"
> [debug] 20594#0: *1 using configuration "/images/"
> [debug] 20594#0: *1 http cl:-1 max:104857600
> [debug] 20594#0: *1 rewrite phase: 2
> [debug] 20594#0: *1 fastimg handler <- My module
> [debug] 20594#0: *1 ngx_http_fastimg_rewrite() uri in: "/images/12/255/0/0.jpg? <- Input uri
> [debug] 20594#0: *1 ngx_http_fastimg_rewrite() uri out: "/images/21/12_255_0_0.jpg? <- Output uri (rewritten)
> [debug] 20594#0: *1 internal redirect: "/images/21/12_255_0_0.jpg?? <- Internal redirect using ngx_http_internal_redirect(r, &uri, NULL)
[...]
> [debug] 20594#0: timer delta: 1
> [debug] 20594#0: worker cycle
> [debug] 20594#0: epoll timer: 60000
> [debug] 20594#0: epoll: fd:20 ev:0005 d:0000000000D4E5B8
> [debug] 20594#0: *1 http upstream request: "0100101 Firefox/?D <- SOMETHING IS BROKE!!
> ?"
> [debug] 20594#0: *1 http upstream process header
Check how do you allocate URI as passed to the
ngx_http_internal_redirect() function. I suspect you are using
stack or other temporary allocated buffer there, and this is what
causes the problem: as long as the buffer is overwritten,
everything is broken. Instead, you should allocate the URI string
as passed to ngx_http_internal_redirect() from the request memory
pool, so it will not be rewritten till the request is freed.
--
Maxim Dounin
http://mdounin.ru/
From kahing at cloudflare.com Tue Jan 15 01:53:42 2019
From: kahing at cloudflare.com (Ka-Hing Cheung)
Date: Mon, 14 Jan 2019 17:53:42 -0800
Subject: cache: move open to thread pool
In-Reply-To: <2a3577f6-4ad4-aa2d-80a2-7e9b715c070d@nginx.com>
References:
<20180808181653.GX56558@mdounin.ru>
<20180810113946.GG56558@mdounin.ru>
<20180903160903.GI56558@mdounin.ru>
<4ba7414a-0eba-6bd3-5a50-2eca591ac25e@nginx.com>
<2a3577f6-4ad4-aa2d-80a2-7e9b715c070d@nginx.com>
Message-ID:
We didn't get to it last year because of other priorities but this is
being worked on. We don't use a vanilla nginx so it takes effort to
integrate your patches. Having a version of this in upstream nginx is
important to us and to me personally.
On Thu, Jan 10, 2019 at 12:30 AM Maxim Konovalov wrote:
>
> So guys, are you really interested in this work beyond shiny
> marketing blog posts?
>
> On 05/12/2018 12:43, Maxim Konovalov wrote:
> > Hello,
> >
> > just a reminder that we are looking for a tester for these patches.
> >
> > Thanks,
> >
> > Maxim
> >
> > On 16/11/2018 12:10, Maxim Konovalov wrote:
> >> Thanks, Ka-Hing, we'll wait for your feedback.
> >>
> >> On 16/11/2018 01:53, Ka-Hing Cheung wrote:
> >>> Hi,
> >>>
> >>> I didn't forget about this. I am pretty swamped at the moment and
> >>> there's a holiday freeze coming up. Will get to his in December.
> >>>
> >>> - Ka-Hing
> >>>
> >>> On Thu, Nov 8, 2018 at 6:19 AM Maxim Konovalov wrote:
> >>>>
> >>>> Hi Ka-Hing,
> >>>>
> >>>> would you mind to test Roman's most recent patches that add
> >>>> "aio_open" directive?
> >>>>
> >>>> http://mailman.nginx.org/pipermail/nginx-devel/2018-November/011538.html
> >>>>
> >>>> We are looking for overall performance and stability metrics and
> >>>> feedback.
> >>>>
> >>>> Much appreciated,
> >>>>
> >>>> Maxim
> >>>>
> >>>> --
> >>>> Maxim Konovalov
> >>
> >>
> >
> >
>
>
> --
> Maxim Konovalov
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
From Elliot.Thomas at bbc.co.uk Wed Jan 16 10:20:59 2019
From: Elliot.Thomas at bbc.co.uk (Elliot Thomas)
Date: Wed, 16 Jan 2019 10:20:59 +0000
Subject: [PATCH] Apply cache locking behaviour to stale cache entries.
In-Reply-To:
References:
<20181210190717.GV99070@mdounin.ru>
Message-ID:
Hello!
With regards to the cache locking on stale patch, are there any further
improvements I should make?
Regards,
Elliot
---
Please ignore the following disclaimer, it?s a bit silly.
I have read the contribution guide, and am fine with it.
-----------------------------
http://www.bbc.co.uk
This e-mail (and any attachments) is confidential and
may contain personal views which are not the views of the BBC unless specifically stated.
If you have received it in
error, please delete it from your system.
Do not use, copy or disclose the
information in any way nor act in reliance on it and notify the sender
immediately.
Please note that the BBC monitors e-mails
sent or received.
Further communication will signify your consent to
this.
-----------------------------
From xeioex at nginx.com Wed Jan 16 15:55:34 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Wed, 16 Jan 2019 15:55:34 +0000
Subject: [njs] Fixed heap-use-after-free introduced in 045ba10db769.
Message-ID:
details: https://hg.nginx.org/njs/rev/4c0de77ef946
branches:
changeset: 728:4c0de77ef946
user: Dmitry Volyntsev
date: Wed Jan 16 18:55:16 2019 +0300
description:
Fixed heap-use-after-free introduced in 045ba10db769.
diffstat:
njs/njs_function.c | 3 ++-
njs/njs_vm.c | 5 ++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diffs (48 lines):
diff -r fb2c2bca61c2 -r 4c0de77ef946 njs/njs_function.c
--- a/njs/njs_function.c Fri Jan 11 19:20:38 2019 +0800
+++ b/njs/njs_function.c Wed Jan 16 18:55:16 2019 +0300
@@ -528,7 +528,6 @@ njs_function_native_call(njs_vm_t *vm, n
frame = vm->top_frame;
vm->top_frame = njs_function_previous_frame(frame);
- njs_function_frame_free(vm, frame);
/*
* If a retval is in a callee arguments scope it
@@ -552,6 +551,8 @@ njs_function_native_call(njs_vm_t *vm, n
*value = vm->retval;
}
+ njs_function_frame_free(vm, frame);
+
return NXT_OK;
}
diff -r fb2c2bca61c2 -r 4c0de77ef946 njs/njs_vm.c
--- a/njs/njs_vm.c Fri Jan 11 19:20:38 2019 +0800
+++ b/njs/njs_vm.c Wed Jan 16 18:55:16 2019 +0300
@@ -2287,12 +2287,15 @@ const njs_vmcode_generic_t njs_continua
static njs_ret_t
njs_vmcode_continuation(njs_vm_t *vm, njs_value_t *invld1, njs_value_t *invld2)
{
+ u_char *return_address;
njs_ret_t ret;
njs_native_frame_t *frame;
njs_continuation_t *cont;
frame = vm->top_frame;
+
cont = njs_vm_continuation(vm);
+ return_address = cont->return_address;
ret = njs_function_native_call(vm, cont->function, frame->arguments,
cont->args_types, frame->nargs,
@@ -2300,7 +2303,7 @@ njs_vmcode_continuation(njs_vm_t *vm, nj
switch (ret) {
case NXT_OK:
- vm->current = cont->return_address;
+ vm->current = return_address;
/* Fall through. */
case NJS_APPLIED:
From sepherosa at gmail.com Thu Jan 17 05:43:57 2019
From: sepherosa at gmail.com (Sepherosa Ziehau)
Date: Thu, 17 Jan 2019 13:43:57 +0800
Subject: aio/unix: Use signal.sival which is standard
In-Reply-To:
References:
Message-ID:
What's the preferred way to handle this? I am not sure whether you
guys allow __FreeBSD_version testing etc.
On Wed, Jan 9, 2019 at 7:52 PM Sergey Kandaurov wrote:
>
>
>
> > On 8 Jan 2019, at 06:37, Sepherosa Ziehau wrote:
> >
> > sigval.sigval is for FreeBSD 6 compability, while FreeBSD 6 was EOL
> > for quite a while.
> >
> > Patch:
> > https://leaf.dragonflybsd.org/~sephe/nginx_sival.diff
>
> Citing here for archives:
>
> commit 14d1cab150226367c8a0f0ae219b0e0571587aea
> Author: Yanmin Qiao
> Date: Tue Jan 8 11:33:00 2019 +0800
>
> unix/aio: Use sigval.sival which is standard.
>
> sigval.sigval is for FreeBSD 6 compability, while FreeBSD 6 was EOL for quite a while.
>
> diff --git a/src/os/unix/ngx_file_aio_read.c b/src/os/unix/ngx_file_aio_read.c
> index aedc3c90..bb60ee82 100644
> --- a/src/os/unix/ngx_file_aio_read.c
> +++ b/src/os/unix/ngx_file_aio_read.c
> @@ -110,7 +110,7 @@ ngx_file_aio_read(ngx_file_t *file, u_char *buf, size_t size, off_t offset,
> #if (NGX_HAVE_KQUEUE)
> aio->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
> aio->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
> - aio->aiocb.aio_sigevent.sigev_value.sigval_ptr = ev;
> + aio->aiocb.aio_sigevent.sigev_value.sival_ptr = ev;
> #endif
> ev->handler = ngx_file_aio_event_handler;
>
>
> FreeBSD 4/5/6 lack sival_ptr (FreeBSD 3 has it, but not yet SIGEV_KEVENT),
> which seemingly was broken in svn r48621 and later restored in r152029.
>
> And that means that the following will no longer be true:
>
> : Currently file AIO is supported on FreeBSD 4.3+ and Linux 2.6.22+ only
>
> While nginx still maintains compatibility down to FreeBSD 2.2.
>
> If applied, it'd need this part as well (used to build on old FreeBSD):
>
> diff --git a/src/event/modules/ngx_eventport_module.c b/src/event/modules/ngx_eventport_module.c
> --- a/src/event/modules/ngx_eventport_module.c
> +++ b/src/event/modules/ngx_eventport_module.c
> @@ -250,9 +250,7 @@ ngx_eventport_init(ngx_cycle_t *cycle, n
>
> ngx_memzero(&sev, sizeof(struct sigevent));
> sev.sigev_notify = SIGEV_PORT;
> -#if !(NGX_TEST_BUILD_EVENTPORT)
> sev.sigev_value.sival_ptr = &pn;
> -#endif
>
> if (timer_create(CLOCK_REALTIME, &sev, &event_timer) == -1) {
> ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
>
> --
> Sergey Kandaurov
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
--
Tomorrow Will Never Die
From pluknet at nginx.com Thu Jan 17 10:29:56 2019
From: pluknet at nginx.com (Sergey Kandaurov)
Date: Thu, 17 Jan 2019 13:29:56 +0300
Subject: aio/unix: Use signal.sival which is standard
In-Reply-To:
References:
Message-ID: <47C75FB8-1DB2-4864-B5DA-13D915E73592@nginx.com>
> On 17 Jan 2019, at 08:43, Sepherosa Ziehau wrote:
>
> What's the preferred way to handle this? I am not sure whether you
> guys allow __FreeBSD_version testing etc.
>
This could be solved with autotests.
# HG changeset patch
# User Sergey Kandaurov
# Date 1547720890 0
# Thu Jan 17 10:28:10 2019 +0000
# Node ID d28513cd71bce227b4e159b7a3f518aa504232f0
# Parent 6d15e452fa2eaf19408e24a0d0fcc3a31344a289
Fixed portability issues with union sigval.
The sival_ptr field is now preferably used.
diff --git a/auto/unix b/auto/unix
--- a/auto/unix
+++ b/auto/unix
@@ -523,6 +523,7 @@ if [ $NGX_FILE_AIO = YES ]; then
ngx_feature_libs=
ngx_feature_test="struct aiocb iocb;
iocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
+ iocb.aio_sigevent.sigev_value.sival_ptr = NULL;
(void) aio_read(&iocb)"
. auto/feature
@@ -532,6 +533,22 @@ if [ $NGX_FILE_AIO = YES ]; then
if [ $ngx_found = no ]; then
+ ngx_feature="kqueue AIO support (legacy)"
+ ngx_feature_name="NGX_HAVE_FILE_AIO_LEGACY"
+ ngx_feature_test="struct aiocb iocb;
+ iocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
+ iocb.aio_sigevent.sigev_value.sigval_ptr = NULL;
+ (void) aio_read(&iocb)"
+ . auto/feature
+
+ if [ $ngx_found = yes ]; then
+ CORE_SRCS="$CORE_SRCS $FILE_AIO_SRCS"
+ have=NGX_HAVE_FILE_AIO . auto/have
+ fi
+ fi
+
+ if [ $ngx_found = no ]; then
+
ngx_feature="Linux AIO support"
ngx_feature_name="NGX_HAVE_FILE_AIO"
ngx_feature_run=no
diff --git a/src/os/unix/ngx_file_aio_read.c b/src/os/unix/ngx_file_aio_read.c
--- a/src/os/unix/ngx_file_aio_read.c
+++ b/src/os/unix/ngx_file_aio_read.c
@@ -110,8 +110,12 @@ ngx_file_aio_read(ngx_file_t *file, u_ch
#if (NGX_HAVE_KQUEUE)
aio->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
aio->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
+#if !(NGX_HAVE_FILE_AIO_LEGACY)
+ aio->aiocb.aio_sigevent.sigev_value.sival_ptr = ev;
+#else
aio->aiocb.aio_sigevent.sigev_value.sigval_ptr = ev;
#endif
+#endif
ev->handler = ngx_file_aio_event_handler;
n = aio_read(&aio->aiocb);
--
Sergey Kandaurov
From vl at nginx.com Thu Jan 17 11:36:27 2019
From: vl at nginx.com (Vladimir Homutov)
Date: Thu, 17 Jan 2019 11:36:27 +0000
Subject: [nginx] Version bump.
Message-ID:
details: https://hg.nginx.org/nginx/rev/134343f2a877
branches:
changeset: 7438:134343f2a877
user: Vladimir Homutov
date: Thu Jan 17 14:31:01 2019 +0300
description:
Version bump.
diffstat:
src/core/nginx.h | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diffs (14 lines):
diff -r 6d15e452fa2e -r 134343f2a877 src/core/nginx.h
--- a/src/core/nginx.h Tue Dec 25 17:53:03 2018 +0300
+++ b/src/core/nginx.h Thu Jan 17 14:31:01 2019 +0300
@@ -9,8 +9,8 @@
#define _NGINX_H_INCLUDED_
-#define nginx_version 1015008
-#define NGINX_VERSION "1.15.8"
+#define nginx_version 1015009
+#define NGINX_VERSION "1.15.9"
#define NGINX_VER "nginx/" NGINX_VERSION
#ifdef NGX_BUILD
From vl at nginx.com Thu Jan 17 11:36:29 2019
From: vl at nginx.com (Vladimir Homutov)
Date: Thu, 17 Jan 2019 11:36:29 +0000
Subject: [nginx] Added the ngx_http_test_required_predicates() function.
Message-ID:
details: https://hg.nginx.org/nginx/rev/5efc23d83bc2
branches:
changeset: 7439:5efc23d83bc2
user: Vladimir Homutov
date: Thu Jan 17 14:31:04 2019 +0300
description:
Added the ngx_http_test_required_predicates() function.
In contrast to ngx_http_test_predicates(), it requires all values to be
non-empty and not equal to "0".
diffstat:
src/http/ngx_http_script.c | 28 ++++++++++++++++++++++++++++
src/http/ngx_http_script.h | 2 ++
2 files changed, 30 insertions(+), 0 deletions(-)
diffs (50 lines):
diff -r 134343f2a877 -r 5efc23d83bc2 src/http/ngx_http_script.c
--- a/src/http/ngx_http_script.c Thu Jan 17 14:31:01 2019 +0300
+++ b/src/http/ngx_http_script.c Thu Jan 17 14:31:04 2019 +0300
@@ -271,6 +271,34 @@ ngx_http_test_predicates(ngx_http_reques
}
+ngx_int_t
+ngx_http_test_required_predicates(ngx_http_request_t *r,
+ ngx_array_t *predicates)
+{
+ ngx_str_t val;
+ ngx_uint_t i;
+ ngx_http_complex_value_t *cv;
+
+ if (predicates == NULL) {
+ return NGX_OK;
+ }
+
+ cv = predicates->elts;
+
+ for (i = 0; i < predicates->nelts; i++) {
+ if (ngx_http_complex_value(r, &cv[i], &val) != NGX_OK) {
+ return NGX_ERROR;
+ }
+
+ if (val.len == 0 || (val.len == 1 && val.data[0] == '0')) {
+ return NGX_DECLINED;
+ }
+ }
+
+ return NGX_OK;
+}
+
+
char *
ngx_http_set_predicate_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
diff -r 134343f2a877 -r 5efc23d83bc2 src/http/ngx_http_script.h
--- a/src/http/ngx_http_script.h Thu Jan 17 14:31:01 2019 +0300
+++ b/src/http/ngx_http_script.h Thu Jan 17 14:31:04 2019 +0300
@@ -214,6 +214,8 @@ char *ngx_http_set_complex_value_slot(ng
ngx_int_t ngx_http_test_predicates(ngx_http_request_t *r,
ngx_array_t *predicates);
+ngx_int_t ngx_http_test_required_predicates(ngx_http_request_t *r,
+ ngx_array_t *predicates);
char *ngx_http_set_predicate_slot(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
From arut at nginx.com Thu Jan 17 12:12:10 2019
From: arut at nginx.com (Roman Arutyunyan)
Date: Thu, 17 Jan 2019 12:12:10 +0000
Subject: [nginx] Prevented scheduling events on a shared connection.
Message-ID:
details: https://hg.nginx.org/nginx/rev/6d4bc025c5a7
branches:
changeset: 7440:6d4bc025c5a7
user: Roman Arutyunyan
date: Mon Jan 14 20:36:23 2019 +0300
description:
Prevented scheduling events on a shared connection.
A shared connection does not own its file descriptor, which means that
ngx_handle_read_event/ngx_handle_write_event calls should do nothing for it.
Currently the c->shared flag is checked in several places in the stream proxy
module prior to calling these functions. However it was not done everywhere.
Missing checks could lead to calling
ngx_handle_read_event/ngx_handle_write_event on shared connections.
The problem manifested itself when using proxy_upload_rate and resulted in
either duplicate file descriptor error (e.g. with epoll) or incorrect further
udp packet processing (e.g. with kqueue).
The fix is to set and reset the event active flag in a way that prevents
ngx_handle_read_event/ngx_handle_write_event from scheduling socket events.
diffstat:
src/event/ngx_event_udp.c | 6 ++++++
src/stream/ngx_stream_proxy_module.c | 4 ++--
2 files changed, 8 insertions(+), 2 deletions(-)
diffs (58 lines):
diff -r 5efc23d83bc2 -r 6d4bc025c5a7 src/event/ngx_event_udp.c
--- a/src/event/ngx_event_udp.c Thu Jan 17 14:31:04 2019 +0300
+++ b/src/event/ngx_event_udp.c Mon Jan 14 20:36:23 2019 +0300
@@ -256,7 +256,9 @@ ngx_event_recvmsg(ngx_event_t *ev)
rev = c->read;
c->udp->buffer = &buf;
+
rev->ready = 1;
+ rev->active = 0;
rev->handler(rev);
@@ -265,6 +267,7 @@ ngx_event_recvmsg(ngx_event_t *ev)
}
rev->ready = 0;
+ rev->active = 1;
goto next;
}
@@ -343,6 +346,7 @@ ngx_event_recvmsg(ngx_event_t *ev)
rev = c->read;
wev = c->write;
+ rev->active = 1;
wev->ready = 1;
rev->log = log;
@@ -453,7 +457,9 @@ ngx_udp_shared_recv(ngx_connection_t *c,
ngx_memcpy(buf, b->pos, n);
c->udp->buffer = NULL;
+
c->read->ready = 0;
+ c->read->active = 1;
return n;
}
diff -r 5efc23d83bc2 -r 6d4bc025c5a7 src/stream/ngx_stream_proxy_module.c
--- a/src/stream/ngx_stream_proxy_module.c Thu Jan 17 14:31:04 2019 +0300
+++ b/src/stream/ngx_stream_proxy_module.c Mon Jan 14 20:36:23 2019 +0300
@@ -1667,13 +1667,13 @@ ngx_stream_proxy_process(ngx_stream_sess
flags = src->read->eof ? NGX_CLOSE_EVENT : 0;
- if (!src->shared && ngx_handle_read_event(src->read, flags) != NGX_OK) {
+ if (ngx_handle_read_event(src->read, flags) != NGX_OK) {
ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
return;
}
if (dst) {
- if (!dst->shared && ngx_handle_write_event(dst->write, 0) != NGX_OK) {
+ if (ngx_handle_write_event(dst->write, 0) != NGX_OK) {
ngx_stream_proxy_finalize(s, NGX_STREAM_INTERNAL_SERVER_ERROR);
return;
}
From arut at nginx.com Thu Jan 17 12:12:12 2019
From: arut at nginx.com (Roman Arutyunyan)
Date: Thu, 17 Jan 2019 12:12:12 +0000
Subject: [nginx] Stream: do not split datagrams when limiting proxy rate.
Message-ID:
details: https://hg.nginx.org/nginx/rev/8acaa1161783
branches:
changeset: 7441:8acaa1161783
user: Roman Arutyunyan
date: Thu Dec 27 19:37:34 2018 +0300
description:
Stream: do not split datagrams when limiting proxy rate.
Previously, when using proxy_upload_rate and proxy_download_rate, the buffer
size for reading from a socket could be reduced as a result of rate limiting.
For connection-oriented protocols this behavior is normal since unread data will
normally be read at the next iteration. But for datagram-oriented protocols
this is not the case, and unread part of the datagram is lost.
Now buffer size is not limited for datagrams. Rate limiting still works in this
case by delaying the next reading event.
diffstat:
src/stream/ngx_stream_proxy_module.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diffs (12 lines):
diff -r 6d4bc025c5a7 -r 8acaa1161783 src/stream/ngx_stream_proxy_module.c
--- a/src/stream/ngx_stream_proxy_module.c Mon Jan 14 20:36:23 2019 +0300
+++ b/src/stream/ngx_stream_proxy_module.c Thu Dec 27 19:37:34 2018 +0300
@@ -1593,7 +1593,7 @@ ngx_stream_proxy_process(ngx_stream_sess
break;
}
- if ((off_t) size > limit) {
+ if (c->type == SOCK_STREAM && (off_t) size > limit) {
size = (size_t) limit;
}
}
From mdounin at mdounin.ru Thu Jan 17 13:22:51 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Thu, 17 Jan 2019 16:22:51 +0300
Subject: aio/unix: Use signal.sival which is standard
In-Reply-To: <47C75FB8-1DB2-4864-B5DA-13D915E73592@nginx.com>
References:
<47C75FB8-1DB2-4864-B5DA-13D915E73592@nginx.com>
Message-ID: <20190117132251.GI99070@mdounin.ru>
Hello!
On Thu, Jan 17, 2019 at 01:29:56PM +0300, Sergey Kandaurov wrote:
>
>
> > On 17 Jan 2019, at 08:43, Sepherosa Ziehau wrote:
> >
> > What's the preferred way to handle this? I am not sure whether you
> > guys allow __FreeBSD_version testing etc.
> >
>
> This could be solved with autotests.
As long as we only care about different FreeBSD versions, this
might as well be an auto/os/freebsd test based on $version, or
just a define based on __FreeBSD_version in
src/os/unix/ngx_freebsd_config.h.
> # HG changeset patch
> # User Sergey Kandaurov
> # Date 1547720890 0
> # Thu Jan 17 10:28:10 2019 +0000
> # Node ID d28513cd71bce227b4e159b7a3f518aa504232f0
> # Parent 6d15e452fa2eaf19408e24a0d0fcc3a31344a289
> Fixed portability issues with union sigval.
>
> The sival_ptr field is now preferably used.
>
> diff --git a/auto/unix b/auto/unix
> --- a/auto/unix
> +++ b/auto/unix
> @@ -523,6 +523,7 @@ if [ $NGX_FILE_AIO = YES ]; then
> ngx_feature_libs=
> ngx_feature_test="struct aiocb iocb;
> iocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
> + iocb.aio_sigevent.sigev_value.sival_ptr = NULL;
> (void) aio_read(&iocb)"
> . auto/feature
>
> @@ -532,6 +533,22 @@ if [ $NGX_FILE_AIO = YES ]; then
>
> if [ $ngx_found = no ]; then
>
> + ngx_feature="kqueue AIO support (legacy)"
> + ngx_feature_name="NGX_HAVE_FILE_AIO_LEGACY"
> + ngx_feature_test="struct aiocb iocb;
> + iocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
> + iocb.aio_sigevent.sigev_value.sigval_ptr = NULL;
> + (void) aio_read(&iocb)"
> + . auto/feature
Note that this will test for "kqueue AIO support (legacy)" on each
Linux build with aio.
> +
> + if [ $ngx_found = yes ]; then
> + CORE_SRCS="$CORE_SRCS $FILE_AIO_SRCS"
> + have=NGX_HAVE_FILE_AIO . auto/have
> + fi
> + fi
> +
> + if [ $ngx_found = no ]; then
> +
> ngx_feature="Linux AIO support"
> ngx_feature_name="NGX_HAVE_FILE_AIO"
> ngx_feature_run=no
> diff --git a/src/os/unix/ngx_file_aio_read.c b/src/os/unix/ngx_file_aio_read.c
> --- a/src/os/unix/ngx_file_aio_read.c
> +++ b/src/os/unix/ngx_file_aio_read.c
> @@ -110,8 +110,12 @@ ngx_file_aio_read(ngx_file_t *file, u_ch
> #if (NGX_HAVE_KQUEUE)
> aio->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
> aio->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
> +#if !(NGX_HAVE_FILE_AIO_LEGACY)
> + aio->aiocb.aio_sigevent.sigev_value.sival_ptr = ev;
> +#else
> aio->aiocb.aio_sigevent.sigev_value.sigval_ptr = ev;
> #endif
> +#endif
> ev->handler = ngx_file_aio_event_handler;
>
> n = aio_read(&aio->aiocb);
A simplier solution might be to always use sival_ptr, and define
it to sigval_ptr on old FreeBSDs.
Alternatively, we can consider dropping file AIO support for these
old FreeBSD versions. This shouldn't be a big deal as this is an
optional feature which is not enabled by default.
--
Maxim Dounin
http://mdounin.ru/
From mdounin at mdounin.ru Thu Jan 17 13:24:02 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Thu, 17 Jan 2019 16:24:02 +0300
Subject: [PATCH] Apply cache locking behaviour to stale cache entries.
In-Reply-To:
References:
<20181210190717.GV99070@mdounin.ru>
Message-ID: <20190117132401.GJ99070@mdounin.ru>
Hello!
On Wed, Jan 16, 2019 at 10:20:59AM +0000, Elliot Thomas wrote:
> With regards to the cache locking on stale patch, are there any further
> improvements I should make?
Sorry, I'm a bit busy with other tasks now. Hopefully I'll
be able to look again at the patch later this month.
--
Maxim Dounin
http://mdounin.ru/
From manickam.subbiah at gmail.com Thu Jan 17 13:57:52 2019
From: manickam.subbiah at gmail.com (Manickam)
Date: Thu, 17 Jan 2019 19:27:52 +0530
Subject: post handler json data
Message-ID:
Hi,
I am new to Nginx development and looking for simple module which just
dumps the input (json format) as is. Looked at different examples available
on net and none of them deals with handling post data. May be i am missing
something and any help is appreciated.
Thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From xeioex at nginx.com Thu Jan 17 14:03:22 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Thu, 17 Jan 2019 14:03:22 +0000
Subject: [njs] Fixed try_break instruction.
Message-ID:
details: https://hg.nginx.org/njs/rev/9973704e2e36
branches:
changeset: 730:9973704e2e36
user: Dmitry Volyntsev
date: Thu Jan 17 16:11:52 2019 +0300
description:
Fixed try_break instruction.
diffstat:
njs/njs_vm.c | 5 ++++-
njs/test/njs_unit_test.c | 3 +++
2 files changed, 7 insertions(+), 1 deletions(-)
diffs (28 lines):
diff -r 0f919fb820e8 -r 9973704e2e36 njs/njs_vm.c
--- a/njs/njs_vm.c Wed Jan 16 18:58:23 2019 +0300
+++ b/njs/njs_vm.c Thu Jan 17 16:11:52 2019 +0300
@@ -2376,7 +2376,10 @@ nxt_noinline njs_ret_t
njs_vmcode_try_break(njs_vm_t *vm, njs_value_t *exit_value,
njs_value_t *offset)
{
- exit_value->data.u.number = 1;
+ /* exit_value can contain valid value set by vmcode_try_return. */
+ if (!njs_is_valid(exit_value)) {
+ exit_value->data.u.number = 1;
+ }
return (njs_ret_t) offset;
}
diff -r 0f919fb820e8 -r 9973704e2e36 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Wed Jan 16 18:58:23 2019 +0300
+++ b/njs/test/njs_unit_test.c Thu Jan 17 16:11:52 2019 +0300
@@ -6902,6 +6902,9 @@ static njs_unit_test_t njs_test[] =
"})(function () {throw 'a'}, 'v')"),
nxt_string("v") },
+ { nxt_string("(function() { try { return ['a'];} finally {} } )()"),
+ nxt_string("a") },
+
{ nxt_string("var o = { valueOf: function() { return '3' } }; --o"),
nxt_string("2") },
From xeioex at nginx.com Thu Jan 17 14:03:22 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Thu, 17 Jan 2019 14:03:22 +0000
Subject: [njs] Making generator block for block statements.
Message-ID:
details: https://hg.nginx.org/njs/rev/0f919fb820e8
branches:
changeset: 729:0f919fb820e8
user: Dmitry Volyntsev
date: Wed Jan 16 18:58:23 2019 +0300
description:
Making generator block for block statements.
diffstat:
njs/njs_generator.c | 28 +++++++++++++++++++
njs/njs_parser.c | 75 +++++++++++++++++++++++++++++++++++++++++++++-------
njs/njs_parser.h | 1 +
3 files changed, 93 insertions(+), 11 deletions(-)
diffs (230 lines):
diff -r 4c0de77ef946 -r 0f919fb820e8 njs/njs_generator.c
--- a/njs/njs_generator.c Wed Jan 16 18:55:16 2019 +0300
+++ b/njs/njs_generator.c Wed Jan 16 18:58:23 2019 +0300
@@ -99,6 +99,8 @@ static nxt_int_t njs_generate_break_stat
njs_generator_t *generator, njs_parser_node_t *node);
static nxt_int_t njs_generate_statement(njs_vm_t *vm,
njs_generator_t *generator, njs_parser_node_t *node);
+static nxt_int_t njs_generate_block_statement(njs_vm_t *vm,
+ njs_generator_t *generator, njs_parser_node_t *node);
static nxt_int_t njs_generate_children(njs_vm_t *vm, njs_generator_t *generator,
njs_parser_node_t *node);
static nxt_int_t njs_generate_stop_statement(njs_vm_t *vm,
@@ -257,6 +259,9 @@ njs_generator(njs_vm_t *vm, njs_generato
case NJS_TOKEN_STATEMENT:
return njs_generate_statement(vm, generator, node);
+ case NJS_TOKEN_BLOCK:
+ return njs_generate_block_statement(vm, generator, node);
+
case NJS_TOKEN_END:
return njs_generate_stop_statement(vm, generator, node);
@@ -1507,6 +1512,29 @@ njs_generate_statement(njs_vm_t *vm, njs
static nxt_int_t
+njs_generate_block_statement(njs_vm_t *vm, njs_generator_t *generator,
+ njs_parser_node_t *node)
+{
+ nxt_int_t ret;
+
+ ret = njs_generate_start_block(vm, generator, NJS_GENERATOR_BLOCK,
+ &no_label);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+
+ ret = njs_generate_statement(vm, generator, node->left);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ return ret;
+ }
+
+ njs_generate_patch_block_exit(vm, generator);
+
+ return ret;
+}
+
+
+static nxt_int_t
njs_generate_children(njs_vm_t *vm, njs_generator_t *generator,
njs_parser_node_t *node)
{
diff -r 4c0de77ef946 -r 0f919fb820e8 njs/njs_parser.c
--- a/njs/njs_parser.c Wed Jan 16 18:55:16 2019 +0300
+++ b/njs/njs_parser.c Wed Jan 16 18:58:23 2019 +0300
@@ -19,6 +19,8 @@ static njs_token_t njs_parser_statement(
njs_token_t token);
static njs_token_t njs_parser_block_statement(njs_vm_t *vm,
njs_parser_t *parser);
+static njs_token_t njs_parser_block(njs_vm_t *vm,
+ njs_parser_t *parser, njs_token_t token);
static njs_token_t njs_parser_function_declaration(njs_vm_t *vm,
njs_parser_t *parser);
static njs_parser_t *njs_parser_function_create(njs_vm_t *vm,
@@ -390,8 +392,9 @@ njs_parser_statement(njs_vm_t *vm, njs_p
static njs_token_t
njs_parser_block_statement(njs_vm_t *vm, njs_parser_t *parser)
{
- njs_ret_t ret;
- njs_token_t token;
+ njs_ret_t ret;
+ njs_token_t token;
+ njs_parser_node_t *node;
token = njs_parser_token(parser);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
@@ -412,12 +415,48 @@ njs_parser_block_statement(njs_vm_t *vm,
}
}
+ if (parser->node != NULL) {
+ /* The statement is not empty block or just semicolon. */
+
+ node = njs_parser_node_alloc(vm);
+ if (nxt_slow_path(node == NULL)) {
+ return NJS_TOKEN_ERROR;
+ }
+
+ node->token = NJS_TOKEN_BLOCK;
+ node->left = parser->node;
+ node->right = NULL;
+ parser->node = node;
+ }
+
njs_parser_scope_end(vm, parser);
return njs_parser_token(parser);
}
+static njs_token_t
+njs_parser_block(njs_vm_t *vm, njs_parser_t *parser, njs_token_t token)
+{
+ njs_parser_node_t *node;
+
+ token = njs_parser_statement(vm, parser, token);
+ if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
+ return token;
+ }
+
+ node = parser->node;
+
+ if (node != NULL && node->token == NJS_TOKEN_BLOCK) {
+ parser->node = node->left;
+
+ nxt_mem_cache_free(vm->mem_cache_pool, node);
+ }
+
+ return token;
+}
+
+
nxt_inline njs_token_t
njs_parser_match(njs_vm_t *vm, njs_parser_t *parser, njs_token_t token,
njs_token_t match)
@@ -933,7 +972,7 @@ njs_parser_if_statement(njs_vm_t *vm, nj
cond = parser->node;
- token = njs_parser_statement(vm, parser, token);
+ token = njs_parser_block(vm, parser, token);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}
@@ -947,7 +986,7 @@ njs_parser_if_statement(njs_vm_t *vm, nj
return token;
}
- token = njs_parser_statement(vm, parser, token);
+ token = njs_parser_block(vm, parser, token);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}
@@ -1104,7 +1143,7 @@ njs_parser_while_statement(njs_vm_t *vm,
cond = parser->node;
- token = njs_parser_statement(vm, parser, token);
+ token = njs_parser_block(vm, parser, token);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}
@@ -1134,7 +1173,7 @@ njs_parser_do_while_statement(njs_vm_t *
return token;
}
- token = njs_parser_statement(vm, parser, token);
+ token = njs_parser_block(vm, parser, token);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}
@@ -1252,7 +1291,7 @@ njs_parser_for_statement(njs_vm_t *vm, n
return token;
}
- token = njs_parser_statement(vm, parser, token);
+ token = njs_parser_block(vm, parser, token);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}
@@ -1418,7 +1457,7 @@ njs_parser_for_var_in_statement(njs_vm_t
return token;
}
- token = njs_parser_statement(vm, parser, token);
+ token = njs_parser_block(vm, parser, token);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}
@@ -1467,7 +1506,7 @@ njs_parser_for_in_statement(njs_vm_t *vm
return token;
}
- token = njs_parser_statement(vm, parser, token);
+ token = njs_parser_block(vm, parser, token);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
}
@@ -1677,14 +1716,28 @@ njs_parser_try_statement(njs_vm_t *vm, n
static njs_token_t
njs_parser_try_block(njs_vm_t *vm, njs_parser_t *parser)
{
- njs_token_t token;
+ njs_token_t token;
+ njs_parser_node_t *node;
token = njs_parser_token(parser);
if (nxt_slow_path(token != NJS_TOKEN_OPEN_BRACE)) {
return NJS_TOKEN_ILLEGAL;
}
- return njs_parser_block_statement(vm, parser);
+ token = njs_parser_block_statement(vm, parser);
+ if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
+ return token;
+ }
+
+ node = parser->node;
+
+ if (node != NULL && node->token == NJS_TOKEN_BLOCK) {
+ parser->node = node->left;
+
+ nxt_mem_cache_free(vm->mem_cache_pool, node);
+ }
+
+ return token;
}
diff -r 4c0de77ef946 -r 0f919fb820e8 njs/njs_parser.h
--- a/njs/njs_parser.h Wed Jan 16 18:55:16 2019 +0300
+++ b/njs/njs_parser.h Wed Jan 16 18:58:23 2019 +0300
@@ -138,6 +138,7 @@ typedef enum {
NJS_TOKEN_EXTERNAL,
NJS_TOKEN_STATEMENT,
+ NJS_TOKEN_BLOCK,
NJS_TOKEN_VAR,
NJS_TOKEN_IF,
NJS_TOKEN_ELSE,
From xeioex at nginx.com Thu Jan 17 14:03:23 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Thu, 17 Jan 2019 14:03:23 +0000
Subject: [njs] Fixed comments "try" instructions.
Message-ID:
details: https://hg.nginx.org/njs/rev/2e9bdb42b3e6
branches:
changeset: 731:2e9bdb42b3e6
user: Dmitry Volyntsev
date: Thu Jan 17 16:12:46 2019 +0300
description:
Fixed comments "try" instructions.
diffstat:
njs/njs_vm.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diffs (21 lines):
diff -r 9973704e2e36 -r 2e9bdb42b3e6 njs/njs_vm.c
--- a/njs/njs_vm.c Thu Jan 17 16:11:52 2019 +0300
+++ b/njs/njs_vm.c Thu Jan 17 16:12:46 2019 +0300
@@ -2386,7 +2386,7 @@ njs_vmcode_try_break(njs_vm_t *vm, njs_v
/*
- * njs_vmcode_try_break() sets exit_value to INVALID -1, and jumps to
+ * njs_vmcode_try_continue() sets exit_value to INVALID -1, and jumps to
* the nearest try_end block. The exit_value is checked by njs_vmcode_finally().
*/
@@ -2401,7 +2401,7 @@ njs_vmcode_try_continue(njs_vm_t *vm, nj
/*
* njs_vmcode_try_return() saves a return value to use it later by
- * njs_vmcode_finally(), and jumps to the nearest try_end block.
+ * njs_vmcode_finally(), and jumps to the nearest try_break block.
*/
nxt_noinline njs_ret_t
From xeioex at nginx.com Thu Jan 17 14:03:23 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Thu, 17 Jan 2019 14:03:23 +0000
Subject: [njs] Setting exit index for try_return instruction is simplified.
Message-ID:
details: https://hg.nginx.org/njs/rev/3b1239c2ee12
branches:
changeset: 732:3b1239c2ee12
user: Dmitry Volyntsev
date: Thu Jan 17 17:01:22 2019 +0300
description:
Setting exit index for try_return instruction is simplified.
diffstat:
njs/njs_generator.c | 57 ++++++++++++----------------------------------------
1 files changed, 13 insertions(+), 44 deletions(-)
diffs (175 lines):
diff -r 2e9bdb42b3e6 -r 3b1239c2ee12 njs/njs_generator.c
--- a/njs/njs_generator.c Thu Jan 17 16:12:46 2019 +0300
+++ b/njs/njs_generator.c Thu Jan 17 17:01:22 2019 +0300
@@ -20,11 +20,6 @@ struct njs_generator_patch_s {
*/
njs_ret_t jump_offset;
njs_generator_patch_t *next;
- /*
- * index_offset is used for patching vmcode_try_return instruction
- * inside try blocks.
- */
- njs_index_t index_offset;
};
@@ -47,6 +42,8 @@ struct njs_generator_block_s {
njs_generator_patch_t *continuation;
njs_generator_patch_t *exit;
njs_generator_block_t *next;
+
+ njs_index_t index;
};
@@ -87,8 +84,6 @@ static nxt_int_t njs_generate_make_conti
njs_generator_t *generator, njs_generator_block_t *block, njs_ret_t offset);
static nxt_noinline void njs_generate_patch_block(njs_vm_t *vm,
njs_generator_t *generator, njs_generator_patch_t *list);
-static nxt_noinline void njs_generate_patch_try_exit_block(njs_vm_t *vm,
- njs_generator_t *generator, njs_generator_patch_t *list, njs_index_t dest);
static nxt_int_t njs_generate_make_exit_patch(njs_vm_t *vm,
njs_generator_t *generator, njs_generator_block_t *block, njs_ret_t offset);
static nxt_noinline void njs_generate_patch_block_exit(njs_vm_t *vm,
@@ -891,7 +886,6 @@ njs_generate_switch_statement(njs_vm_t *
return NXT_ERROR;
}
- patch->index_offset = 0;
patch->jump_offset = njs_code_offset(generator, equal)
+ offsetof(njs_vmcode_equal_jump_t, offset);
@@ -1277,6 +1271,8 @@ njs_generate_start_block(njs_vm_t *vm, n
block->continuation = NULL;
block->exit = NULL;
+ block->index = 0;
+
return NXT_OK;
}
@@ -1315,7 +1311,6 @@ njs_generate_make_continuation_patch(njs
patch->next = block->continuation;
block->continuation = patch;
- patch->index_offset = 0;
patch->jump_offset = offset;
return NXT_OK;
@@ -1337,25 +1332,6 @@ njs_generate_patch_block(njs_vm_t *vm, n
}
-static nxt_noinline void
-njs_generate_patch_try_exit_block(njs_vm_t *vm, njs_generator_t *generator,
- njs_generator_patch_t *list, njs_index_t dest)
-{
- njs_generator_patch_t *patch, *next;
-
- for (patch = list; patch != NULL; patch = next) {
- njs_code_update_offset(generator, patch);
- next = patch->next;
-
- if (patch->index_offset != 0) {
- *(njs_code_ptr(generator, njs_index_t, patch->index_offset)) = dest;
- }
-
- nxt_mem_cache_free(vm->mem_cache_pool, patch);
- }
-}
-
-
static nxt_int_t
njs_generate_make_exit_patch(njs_vm_t *vm, njs_generator_t *generator,
njs_generator_block_t *block, njs_ret_t offset)
@@ -1372,7 +1348,6 @@ njs_generate_make_exit_patch(njs_vm_t *v
patch->next = block->exit;
block->exit = patch;
- patch->index_offset = 0;
patch->jump_offset = offset;
return NXT_OK;
@@ -1429,7 +1404,6 @@ njs_generate_continue_statement(njs_vm_t
jump->code.retval = NJS_VMCODE_NO_RETVAL;
jump->offset = offsetof(njs_vmcode_jump_t, offset);
- patch->index_offset = 0;
patch->jump_offset = njs_code_offset(generator, jump)
+ offsetof(njs_vmcode_jump_t, offset);
}
@@ -1480,7 +1454,6 @@ njs_generate_break_statement(njs_vm_t *v
jump->code.retval = NJS_VMCODE_NO_RETVAL;
jump->offset = offsetof(njs_vmcode_jump_t, offset);
- patch->index_offset = 0;
patch->jump_offset = njs_code_offset(generator, jump)
+ offsetof(njs_vmcode_jump_t, offset);
}
@@ -2533,10 +2506,7 @@ njs_generate_return_statement(njs_vm_t *
try_return->code.operands = NJS_VMCODE_2OPERANDS;
try_return->code.retval = NJS_VMCODE_RETVAL;
try_return->retval = index;
-
- try_return->save = index;
- patch->index_offset = njs_code_offset(generator, try_return)
- + offsetof(njs_vmcode_try_return_t, save);
+ try_return->save = block->index;
try_return->offset = offsetof(njs_vmcode_try_return_t, offset);
patch->jump_offset = njs_code_offset(generator, try_return)
@@ -2739,13 +2709,14 @@ njs_generate_try_statement(njs_vm_t *vm,
return ret;
}
+ try_block = generator->block;
+ try_block->index = exit_index;
+
ret = njs_generator(vm, generator, node->left);
if (nxt_slow_path(ret != NXT_OK)) {
return ret;
}
- try_block = generator->block;
-
njs_generate_code(generator, njs_vmcode_try_end_t, try_end);
try_end_offset = njs_code_offset(generator, try_end);
try_end->code.operation = njs_vmcode_try_end;
@@ -2753,8 +2724,7 @@ njs_generate_try_statement(njs_vm_t *vm,
try_end->code.retval = NJS_VMCODE_NO_RETVAL;
if (try_block->exit != NULL) {
- njs_generate_patch_try_exit_block(vm, generator, try_block->exit,
- exit_index);
+ njs_generate_patch_block(vm, generator, try_block->exit);
njs_generate_code(generator, njs_vmcode_try_trampoline_t, try_break);
try_break->code.operation = njs_vmcode_try_break;
@@ -2876,13 +2846,14 @@ njs_generate_try_statement(njs_vm_t *vm,
return ret;
}
+ catch_block = generator->block;
+ catch_block->index = exit_index;
+
ret = njs_generator(vm, generator, node->left->right);
if (nxt_slow_path(ret != NXT_OK)) {
return ret;
}
- catch_block = generator->block;
-
njs_generate_code(generator, njs_vmcode_try_end_t, catch_end);
catch_end_offset = njs_code_offset(generator, catch_end);
catch_end->code.operation = njs_vmcode_try_end;
@@ -2890,9 +2861,7 @@ njs_generate_try_statement(njs_vm_t *vm,
catch_end->code.retval = NJS_VMCODE_NO_RETVAL;
if (catch_block->exit != NULL) {
- njs_generate_patch_try_exit_block(vm, generator,
- catch_block->exit,
- exit_index);
+ njs_generate_patch_block(vm, generator, catch_block->exit);
njs_generate_code(generator, njs_vmcode_try_trampoline_t,
try_break);
From pluknet at nginx.com Thu Jan 17 15:18:29 2019
From: pluknet at nginx.com (Sergey Kandaurov)
Date: Thu, 17 Jan 2019 18:18:29 +0300
Subject: aio/unix: Use signal.sival which is standard
In-Reply-To: <20190117132251.GI99070@mdounin.ru>
References:
<47C75FB8-1DB2-4864-B5DA-13D915E73592@nginx.com>
<20190117132251.GI99070@mdounin.ru>
Message-ID: <76EB7D89-8048-4CB5-AB87-A94C2C52F808@nginx.com>
> On 17 Jan 2019, at 16:22, Maxim Dounin wrote:
>
> Hello!
>
> On Thu, Jan 17, 2019 at 01:29:56PM +0300, Sergey Kandaurov wrote:
>
>>
>>
>>> On 17 Jan 2019, at 08:43, Sepherosa Ziehau wrote:
>>>
>>> What's the preferred way to handle this? I am not sure whether you
>>> guys allow __FreeBSD_version testing etc.
>>>
>>
>> This could be solved with autotests.
>
> As long as we only care about different FreeBSD versions, this
> might as well be an auto/os/freebsd test based on $version, or
> just a define based on __FreeBSD_version in
> src/os/unix/ngx_freebsd_config.h.
>
>> # HG changeset patch
>> # User Sergey Kandaurov
>> # Date 1547720890 0
>> # Thu Jan 17 10:28:10 2019 +0000
>> # Node ID d28513cd71bce227b4e159b7a3f518aa504232f0
>> # Parent 6d15e452fa2eaf19408e24a0d0fcc3a31344a289
>> Fixed portability issues with union sigval.
>>
>> The sival_ptr field is now preferably used.
>>
>> diff --git a/auto/unix b/auto/unix
>> --- a/auto/unix
>> +++ b/auto/unix
>> @@ -523,6 +523,7 @@ if [ $NGX_FILE_AIO = YES ]; then
>> ngx_feature_libs=
>> ngx_feature_test="struct aiocb iocb;
>> iocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
>> + iocb.aio_sigevent.sigev_value.sival_ptr = NULL;
>> (void) aio_read(&iocb)"
>> . auto/feature
>>
>> @@ -532,6 +533,22 @@ if [ $NGX_FILE_AIO = YES ]; then
>>
>> if [ $ngx_found = no ]; then
>>
>> + ngx_feature="kqueue AIO support (legacy)"
>> + ngx_feature_name="NGX_HAVE_FILE_AIO_LEGACY"
>> + ngx_feature_test="struct aiocb iocb;
>> + iocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
>> + iocb.aio_sigevent.sigev_value.sigval_ptr = NULL;
>> + (void) aio_read(&iocb)"
>> + . auto/feature
>
> Note that this will test for "kqueue AIO support (legacy)" on each
> Linux build with aio.
That is unfortunate.
>> +
>> + if [ $ngx_found = yes ]; then
>> + CORE_SRCS="$CORE_SRCS $FILE_AIO_SRCS"
>> + have=NGX_HAVE_FILE_AIO . auto/have
>> + fi
>> + fi
>> +
>> + if [ $ngx_found = no ]; then
>> +
>> ngx_feature="Linux AIO support"
>> ngx_feature_name="NGX_HAVE_FILE_AIO"
>> ngx_feature_run=no
>> diff --git a/src/os/unix/ngx_file_aio_read.c b/src/os/unix/ngx_file_aio_read.c
>> --- a/src/os/unix/ngx_file_aio_read.c
>> +++ b/src/os/unix/ngx_file_aio_read.c
>> @@ -110,8 +110,12 @@ ngx_file_aio_read(ngx_file_t *file, u_ch
>> #if (NGX_HAVE_KQUEUE)
>> aio->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
>> aio->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
>> +#if !(NGX_HAVE_FILE_AIO_LEGACY)
>> + aio->aiocb.aio_sigevent.sigev_value.sival_ptr = ev;
>> +#else
>> aio->aiocb.aio_sigevent.sigev_value.sigval_ptr = ev;
>> #endif
>> +#endif
>> ev->handler = ngx_file_aio_event_handler;
>>
>> n = aio_read(&aio->aiocb);
>
> A simplier solution might be to always use sival_ptr, and define
> it to sigval_ptr on old FreeBSDs.
This looks simpler indeed.
> Alternatively, we can consider dropping file AIO support for these
> old FreeBSD versions. This shouldn't be a big deal as this is an
> optional feature which is not enabled by default.
And that's what I'd prefer for --test-build-eventport workaround.
What about these patches?
For DragonFly this should effectively match initial submission.
# HG changeset patch
# User Sergey Kandaurov
# Date 1547734251 0
# Thu Jan 17 14:10:51 2019 +0000
# Node ID baab2b35e8cc79cfdf9924d1752348e97c1da13e
# Parent 6d15e452fa2eaf19408e24a0d0fcc3a31344a289
Fixed portability issues with union sigval.
diff --git a/src/os/unix/ngx_file_aio_read.c b/src/os/unix/ngx_file_aio_read.c
--- a/src/os/unix/ngx_file_aio_read.c
+++ b/src/os/unix/ngx_file_aio_read.c
@@ -110,7 +110,7 @@ ngx_file_aio_read(ngx_file_t *file, u_ch
#if (NGX_HAVE_KQUEUE)
aio->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
aio->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
- aio->aiocb.aio_sigevent.sigev_value.sigval_ptr = ev;
+ aio->aiocb.aio_sigevent.sigev_value.sival_ptr = ev;
#endif
ev->handler = ngx_file_aio_event_handler;
diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h
--- a/src/os/unix/ngx_freebsd_config.h
+++ b/src/os/unix/ngx_freebsd_config.h
@@ -91,6 +91,10 @@
#if (NGX_HAVE_FILE_AIO)
#include
typedef struct aiocb ngx_aiocb_t;
+
+#if (__FreeBSD_version < 700005 && !defined __DragonFly__)
+#define sival_ptr sigval_ptr
+#endif
#endif
# HG changeset patch
# User Sergey Kandaurov
# Date 1547736673 0
# Thu Jan 17 14:51:13 2019 +0000
# Node ID c66911fc9924a60bb5d691ca00bc2fb1c3032866
# Parent baab2b35e8cc79cfdf9924d1752348e97c1da13e
Removed --test-build-eventport workaround for old FreeBSD versions.
diff --git a/src/event/modules/ngx_eventport_module.c b/src/event/modules/ngx_eventport_module.c
--- a/src/event/modules/ngx_eventport_module.c
+++ b/src/event/modules/ngx_eventport_module.c
@@ -250,9 +250,7 @@ ngx_eventport_init(ngx_cycle_t *cycle, n
ngx_memzero(&sev, sizeof(struct sigevent));
sev.sigev_notify = SIGEV_PORT;
-#if !(NGX_TEST_BUILD_EVENTPORT)
sev.sigev_value.sival_ptr = &pn;
-#endif
if (timer_create(CLOCK_REALTIME, &sev, &event_timer) == -1) {
ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
--
Sergey Kandaurov
From yuchen at cloudflare.com Thu Jan 17 19:28:54 2019
From: yuchen at cloudflare.com (Yuchen Wu)
Date: Thu, 17 Jan 2019 11:28:54 -0800
Subject: [PATCH] Be consistent with keepalive during graceful shutdown
Message-ID: <8a6290c41b33c664d52d.1547753334@YuchenDev>
# HG changeset patch
# User Yuchen Wu
# Date 1547749157 28800
# Thu Jan 17 10:19:17 2019 -0800
# Node ID 8a6290c41b33c664d52d7a472400381e71ecf171
# Parent 8acaa1161783347106dcaea574837e441e13b540
Be consistent with keepalive during graceful shutdown
Before, when nginx sends the Connection: Keep-Alive header and then
nginx decides to shutdown, it will close the connection. Downstream
may already reuse the connection for another request in the meanwhile.
This change allows one extra use of such a connection to make sure it
is closed cleanly.
diff -r 8acaa1161783 -r 8a6290c41b33 src/http/ngx_http_header_filter_module.c
--- a/src/http/ngx_http_header_filter_module.c Thu Dec 27 19:37:34 2018 +0300
+++ b/src/http/ngx_http_header_filter_module.c Thu Jan 17 10:19:17 2019 -0800
@@ -187,6 +187,10 @@
r->header_only = 1;
}
+ if (ngx_terminate || ngx_exiting) {
+ r->keepalive = 0;
+ }
+
if (r->headers_out.last_modified_time != -1) {
if (r->headers_out.status != NGX_HTTP_OK
&& r->headers_out.status != NGX_HTTP_PARTIAL_CONTENT
diff -r 8acaa1161783 -r 8a6290c41b33 src/http/ngx_http_request.c
--- a/src/http/ngx_http_request.c Thu Dec 27 19:37:34 2018 +0300
+++ b/src/http/ngx_http_request.c Thu Jan 17 10:19:17 2019 -0800
@@ -2611,9 +2611,7 @@
r->lingering_close = 1;
}
- if (!ngx_terminate
- && !ngx_exiting
- && r->keepalive
+ if (r->keepalive
&& clcf->keepalive_timeout > 0)
{
ngx_http_set_keepalive(r);
From hungnv at opensource.com.vn Fri Jan 18 02:28:00 2019
From: hungnv at opensource.com.vn (Hung Nguyen)
Date: Fri, 18 Jan 2019 09:28:00 +0700
Subject: post handler json data
In-Reply-To:
References:
Message-ID: <654CEB36-9C6F-410F-B514-B056B437F9CA@opensource.com.vn>
Hello,
With this type of purpose I personally think you should take a look at njs instead of writing nginx module. Json can be done easier with JS
--
H?ng
> On Jan 17, 2019, at 20:57, Manickam wrote:
>
> Hi,
>
> I am new to Nginx development and looking for simple module which just dumps the input (json format) as is. Looked at different examples available on net and none of them deals with handling post data. May be i am missing something and any help is appreciated.
>
> Thanks in advance
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
From sepherosa at gmail.com Fri Jan 18 07:39:50 2019
From: sepherosa at gmail.com (Sepherosa Ziehau)
Date: Fri, 18 Jan 2019 15:39:50 +0800
Subject: aio/unix: Use signal.sival which is standard
In-Reply-To: <76EB7D89-8048-4CB5-AB87-A94C2C52F808@nginx.com>
References:
<47C75FB8-1DB2-4864-B5DA-13D915E73592@nginx.com>
<20190117132251.GI99070@mdounin.ru>
<76EB7D89-8048-4CB5-AB87-A94C2C52F808@nginx.com>
Message-ID:
Hi,
> diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h
> --- a/src/os/unix/ngx_freebsd_config.h
> +++ b/src/os/unix/ngx_freebsd_config.h
> @@ -91,6 +91,10 @@
> #if (NGX_HAVE_FILE_AIO)
> #include
> typedef struct aiocb ngx_aiocb_t;
> +
> +#if (__FreeBSD_version < 700005 && !defined __DragonFly__)
> +#define sival_ptr sigval_ptr
> +#endif
> #endif
Will the following code be more straightforward?
#if defined(__FreeBSD__) && (__FreeBSD_version < 700005)
#define sival_ptr sigval_ptr
#endif
Thanks,
sephe
--
Tomorrow Will Never Die
From pluknet at nginx.com Fri Jan 18 10:22:39 2019
From: pluknet at nginx.com (Sergey Kandaurov)
Date: Fri, 18 Jan 2019 13:22:39 +0300
Subject: aio/unix: Use signal.sival which is standard
In-Reply-To:
References:
<47C75FB8-1DB2-4864-B5DA-13D915E73592@nginx.com>
<20190117132251.GI99070@mdounin.ru>
<76EB7D89-8048-4CB5-AB87-A94C2C52F808@nginx.com>
Message-ID: <80C7E6D7-4FBE-471B-A53D-D0FB777EA88E@nginx.com>
> On 18 Jan 2019, at 10:39, Sepherosa Ziehau wrote:
>
> Hi,
>
>> diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h
>> --- a/src/os/unix/ngx_freebsd_config.h
>> +++ b/src/os/unix/ngx_freebsd_config.h
>> @@ -91,6 +91,10 @@
>> #if (NGX_HAVE_FILE_AIO)
>> #include
>> typedef struct aiocb ngx_aiocb_t;
>> +
>> +#if (__FreeBSD_version < 700005 && !defined __DragonFly__)
>> +#define sival_ptr sigval_ptr
>> +#endif
>> #endif
>
> Will the following code be more straightforward?
> #if defined(__FreeBSD__) && (__FreeBSD_version < 700005)
> #define sival_ptr sigval_ptr
> #endif
This won't work. __FreeBSD__ and__FreeBSD_version
are defined for DragonFly in src/core/ngx_config.h.
--
Sergey Kandaurov
From xeioex at nginx.com Fri Jan 18 11:51:13 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Fri, 18 Jan 2019 11:51:13 +0000
Subject: [njs] Style.
Message-ID:
details: https://hg.nginx.org/njs/rev/1ebf0773c44f
branches:
changeset: 733:1ebf0773c44f
user: Dmitry Volyntsev
date: Fri Jan 18 14:50:50 2019 +0300
description:
Style.
diffstat:
njs/njs_extern.c | 2 +-
njs/njs_generator.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diffs (24 lines):
diff -r 3b1239c2ee12 -r 1ebf0773c44f njs/njs_extern.c
--- a/njs/njs_extern.c Thu Jan 17 17:01:22 2019 +0300
+++ b/njs/njs_extern.c Fri Jan 18 14:50:50 2019 +0300
@@ -173,7 +173,7 @@ njs_vm_external_prototype(njs_vm_t *vm,
nxt_int_t
njs_vm_external_create(njs_vm_t *vm, njs_value_t *ext_val,
- const njs_extern_t *proto, njs_external_ptr_t object)
+ const njs_extern_t *proto, njs_external_ptr_t object)
{
void *obj;
diff -r 3b1239c2ee12 -r 1ebf0773c44f njs/njs_generator.c
--- a/njs/njs_generator.c Thu Jan 17 17:01:22 2019 +0300
+++ b/njs/njs_generator.c Fri Jan 18 14:50:50 2019 +0300
@@ -817,7 +817,7 @@ njs_generate_switch_statement(njs_vm_t *
njs_parser_node_t *node, *expr, *branch;
njs_vmcode_move_t *move;
njs_vmcode_jump_t *jump;
- njs_generator_patch_t *patch, *next, *patches, **last;
+ njs_generator_patch_t *patch, *next, *patches, **last;
njs_vmcode_equal_jump_t *equal;
/* The "switch" expression. */
From xeioex at nginx.com Fri Jan 18 12:28:32 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Fri, 18 Jan 2019 12:28:32 +0000
Subject: [njs] Removed unused vm->scratch field.
Message-ID:
details: https://hg.nginx.org/njs/rev/0813395557b6
branches:
changeset: 734:0813395557b6
user: Dmitry Volyntsev
date: Fri Jan 18 15:28:17 2019 +0300
description:
Removed unused vm->scratch field.
diffstat:
njs/njs_vm.h | 6 ------
1 files changed, 0 insertions(+), 6 deletions(-)
diffs (16 lines):
diff -r 1ebf0773c44f -r 0813395557b6 njs/njs_vm.h
--- a/njs/njs_vm.h Fri Jan 18 14:50:50 2019 +0300
+++ b/njs/njs_vm.h Fri Jan 18 15:28:17 2019 +0300
@@ -1021,12 +1021,6 @@ struct njs_vm_s {
/* njs_vm_t must be aligned to njs_value_t due to scratch value. */
njs_value_t retval;
- /*
- * The scratch value is used for lvalue operations on nonexistent
- * properties of non-object values: "a = 1; a.b++".
- */
- njs_value_t scratch;
-
u_char *current;
njs_value_t *scopes[NJS_SCOPES];
From mdounin at mdounin.ru Mon Jan 21 15:17:16 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Mon, 21 Jan 2019 18:17:16 +0300
Subject: [PATCH] Be consistent with keepalive during graceful shutdown
In-Reply-To: <8a6290c41b33c664d52d.1547753334@YuchenDev>
References: <8a6290c41b33c664d52d.1547753334@YuchenDev>
Message-ID: <20190121151716.GB1877@mdounin.ru>
Hello!
On Thu, Jan 17, 2019 at 11:28:54AM -0800, Yuchen Wu via nginx-devel wrote:
> # HG changeset patch
> # User Yuchen Wu
> # Date 1547749157 28800
> # Thu Jan 17 10:19:17 2019 -0800
> # Node ID 8a6290c41b33c664d52d7a472400381e71ecf171
> # Parent 8acaa1161783347106dcaea574837e441e13b540
> Be consistent with keepalive during graceful shutdown
>
> Before, when nginx sends the Connection: Keep-Alive header and then
> nginx decides to shutdown, it will close the connection. Downstream
> may already reuse the connection for another request in the meanwhile.
>
> This change allows one extra use of such a connection to make sure it
> is closed cleanly.
>
> diff -r 8acaa1161783 -r 8a6290c41b33 src/http/ngx_http_header_filter_module.c
> --- a/src/http/ngx_http_header_filter_module.c Thu Dec 27 19:37:34 2018 +0300
> +++ b/src/http/ngx_http_header_filter_module.c Thu Jan 17 10:19:17 2019 -0800
> @@ -187,6 +187,10 @@
> r->header_only = 1;
> }
>
> + if (ngx_terminate || ngx_exiting) {
> + r->keepalive = 0;
> + }
> +
> if (r->headers_out.last_modified_time != -1) {
> if (r->headers_out.status != NGX_HTTP_OK
> && r->headers_out.status != NGX_HTTP_PARTIAL_CONTENT
> diff -r 8acaa1161783 -r 8a6290c41b33 src/http/ngx_http_request.c
> --- a/src/http/ngx_http_request.c Thu Dec 27 19:37:34 2018 +0300
> +++ b/src/http/ngx_http_request.c Thu Jan 17 10:19:17 2019 -0800
> @@ -2611,9 +2611,7 @@
> r->lingering_close = 1;
> }
>
> - if (!ngx_terminate
> - && !ngx_exiting
> - && r->keepalive
> + if (r->keepalive
> && clcf->keepalive_timeout > 0)
> {
> ngx_http_set_keepalive(r);
Thank you for the patch.
Some notes, in no particular order:
- As per HTTP RFC, clients are expected to be prepared to
connection close even if there is no "Connection: close" header,
https://tools.ietf.org/html/rfc2616#section-8.1.4:
A client, server, or proxy MAY close the transport connection at any
time. For example, a client might have started to send a new request
at the same time that the server has decided to close the "idle"
connection. From the server's point of view, the connection is being
closed while it was idle, but from the client's point of view, a
request is in progress.
This means that clients, servers, and proxies MUST be able to recover
from asynchronous close events. Client software SHOULD reopen the
transport connection and retransmit the aborted sequence of requests
without user interaction so long as the request sequence is
idempotent (see section 9.1.2).
Given this, nginx more or less doesn't care when it closes idle
(keepalive) connections. In particular, it does so when
keepalive_timeout expires (which can be quite low), on graceful
shutdown of worker process, and also when there isn't enough
worker_connections.
- Waiting for another request on graceful shutdown means that old
worker processes will be running for keepalive_timeout time even
if there are no requests in progress. While this might not be
important for configurations where are requests in progress for
significantly longer time, this is an important change for
configurations where normally no in-progress requests and so
configuration reloads are more or less immediate now. This should
be carefully considered before changing the behaviour (if at all).
- The patch suggested introduces inconsistency between handling of
connections which were moved to keepalive before shutdown was
requested, and connections which are moving to keepalive after
this point.
- The patch suggested introduces connections which are in idle
state, yet not closed after a shutdown request. There should be
no such connections, and the fact that such connections are not
closed immediately is a result of an optimization, see
http://hg.nginx.org/nginx/rev/5e6142609e48.
If you want to improve keepalive connection handling on shutdown /
configuration reload, you may want to focus on less intrusive
changes, in particular:
- Reset r->keepalive on shutdown if it is still possible (as
ngx_http_header_filter_module.c part of your patch does).
- Try to process pipelined requests if there are any if nginx
worker is shutting down but wasn't yet able to announce
"Connection: close" to the client.
--
Maxim Dounin
http://mdounin.ru/
From mdounin at mdounin.ru Tue Jan 22 14:54:29 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Tue, 22 Jan 2019 17:54:29 +0300
Subject: aio/unix: Use signal.sival which is standard
In-Reply-To: <76EB7D89-8048-4CB5-AB87-A94C2C52F808@nginx.com>
References:
<47C75FB8-1DB2-4864-B5DA-13D915E73592@nginx.com>
<20190117132251.GI99070@mdounin.ru>
<76EB7D89-8048-4CB5-AB87-A94C2C52F808@nginx.com>
Message-ID: <20190122145429.GE1877@mdounin.ru>
Hello!
On Thu, Jan 17, 2019 at 06:18:29PM +0300, Sergey Kandaurov wrote:
>
> > On 17 Jan 2019, at 16:22, Maxim Dounin wrote:
> >
> > Hello!
> >
> > On Thu, Jan 17, 2019 at 01:29:56PM +0300, Sergey Kandaurov wrote:
> >
> >>
> >>
> >>> On 17 Jan 2019, at 08:43, Sepherosa Ziehau wrote:
> >>>
> >>> What's the preferred way to handle this? I am not sure whether you
> >>> guys allow __FreeBSD_version testing etc.
> >>>
> >>
> >> This could be solved with autotests.
> >
> > As long as we only care about different FreeBSD versions, this
> > might as well be an auto/os/freebsd test based on $version, or
> > just a define based on __FreeBSD_version in
> > src/os/unix/ngx_freebsd_config.h.
> >
> >> # HG changeset patch
> >> # User Sergey Kandaurov
> >> # Date 1547720890 0
> >> # Thu Jan 17 10:28:10 2019 +0000
> >> # Node ID d28513cd71bce227b4e159b7a3f518aa504232f0
> >> # Parent 6d15e452fa2eaf19408e24a0d0fcc3a31344a289
> >> Fixed portability issues with union sigval.
> >>
> >> The sival_ptr field is now preferably used.
> >>
> >> diff --git a/auto/unix b/auto/unix
> >> --- a/auto/unix
> >> +++ b/auto/unix
> >> @@ -523,6 +523,7 @@ if [ $NGX_FILE_AIO = YES ]; then
> >> ngx_feature_libs=
> >> ngx_feature_test="struct aiocb iocb;
> >> iocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
> >> + iocb.aio_sigevent.sigev_value.sival_ptr = NULL;
> >> (void) aio_read(&iocb)"
> >> . auto/feature
> >>
> >> @@ -532,6 +533,22 @@ if [ $NGX_FILE_AIO = YES ]; then
> >>
> >> if [ $ngx_found = no ]; then
> >>
> >> + ngx_feature="kqueue AIO support (legacy)"
> >> + ngx_feature_name="NGX_HAVE_FILE_AIO_LEGACY"
> >> + ngx_feature_test="struct aiocb iocb;
> >> + iocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
> >> + iocb.aio_sigevent.sigev_value.sigval_ptr = NULL;
> >> + (void) aio_read(&iocb)"
> >> + . auto/feature
> >
> > Note that this will test for "kqueue AIO support (legacy)" on each
> > Linux build with aio.
>
> That is unfortunate.
>
> >> +
> >> + if [ $ngx_found = yes ]; then
> >> + CORE_SRCS="$CORE_SRCS $FILE_AIO_SRCS"
> >> + have=NGX_HAVE_FILE_AIO . auto/have
> >> + fi
> >> + fi
> >> +
> >> + if [ $ngx_found = no ]; then
> >> +
> >> ngx_feature="Linux AIO support"
> >> ngx_feature_name="NGX_HAVE_FILE_AIO"
> >> ngx_feature_run=no
> >> diff --git a/src/os/unix/ngx_file_aio_read.c b/src/os/unix/ngx_file_aio_read.c
> >> --- a/src/os/unix/ngx_file_aio_read.c
> >> +++ b/src/os/unix/ngx_file_aio_read.c
> >> @@ -110,8 +110,12 @@ ngx_file_aio_read(ngx_file_t *file, u_ch
> >> #if (NGX_HAVE_KQUEUE)
> >> aio->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
> >> aio->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
> >> +#if !(NGX_HAVE_FILE_AIO_LEGACY)
> >> + aio->aiocb.aio_sigevent.sigev_value.sival_ptr = ev;
> >> +#else
> >> aio->aiocb.aio_sigevent.sigev_value.sigval_ptr = ev;
> >> #endif
> >> +#endif
> >> ev->handler = ngx_file_aio_event_handler;
> >>
> >> n = aio_read(&aio->aiocb);
> >
> > A simplier solution might be to always use sival_ptr, and define
> > it to sigval_ptr on old FreeBSDs.
>
> This looks simpler indeed.
>
> > Alternatively, we can consider dropping file AIO support for these
> > old FreeBSD versions. This shouldn't be a big deal as this is an
> > optional feature which is not enabled by default.
>
> And that's what I'd prefer for --test-build-eventport workaround.
>
> What about these patches?
> For DragonFly this should effectively match initial submission.
>
> # HG changeset patch
> # User Sergey Kandaurov
> # Date 1547734251 0
> # Thu Jan 17 14:10:51 2019 +0000
> # Node ID baab2b35e8cc79cfdf9924d1752348e97c1da13e
> # Parent 6d15e452fa2eaf19408e24a0d0fcc3a31344a289
> Fixed portability issues with union sigval.
This needs to be extended with some background information -
notably why it used to be sigval_ptr, and why to switch to
sival_ptr.
>
> diff --git a/src/os/unix/ngx_file_aio_read.c b/src/os/unix/ngx_file_aio_read.c
> --- a/src/os/unix/ngx_file_aio_read.c
> +++ b/src/os/unix/ngx_file_aio_read.c
> @@ -110,7 +110,7 @@ ngx_file_aio_read(ngx_file_t *file, u_ch
> #if (NGX_HAVE_KQUEUE)
> aio->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
> aio->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
> - aio->aiocb.aio_sigevent.sigev_value.sigval_ptr = ev;
> + aio->aiocb.aio_sigevent.sigev_value.sival_ptr = ev;
> #endif
> ev->handler = ngx_file_aio_event_handler;
>
> diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h
> --- a/src/os/unix/ngx_freebsd_config.h
> +++ b/src/os/unix/ngx_freebsd_config.h
> @@ -91,6 +91,10 @@
> #if (NGX_HAVE_FILE_AIO)
> #include
> typedef struct aiocb ngx_aiocb_t;
> +
> +#if (__FreeBSD_version < 700005 && !defined __DragonFly__)
> +#define sival_ptr sigval_ptr
> +#endif
> #endif
>
>
Minor style nits:
diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h
--- a/src/os/unix/ngx_freebsd_config.h
+++ b/src/os/unix/ngx_freebsd_config.h
@@ -89,12 +89,14 @@
#if (NGX_HAVE_FILE_AIO)
+
#include
typedef struct aiocb ngx_aiocb_t;
#if (__FreeBSD_version < 700005 && !defined __DragonFly__)
-#define sival_ptr sigval_ptr
+#define sival_ptr sigval_ptr
#endif
+
#endif
> # HG changeset patch
> # User Sergey Kandaurov
> # Date 1547736673 0
> # Thu Jan 17 14:51:13 2019 +0000
> # Node ID c66911fc9924a60bb5d691ca00bc2fb1c3032866
> # Parent baab2b35e8cc79cfdf9924d1752348e97c1da13e
> Removed --test-build-eventport workaround for old FreeBSD versions.
>
> diff --git a/src/event/modules/ngx_eventport_module.c b/src/event/modules/ngx_eventport_module.c
> --- a/src/event/modules/ngx_eventport_module.c
> +++ b/src/event/modules/ngx_eventport_module.c
> @@ -250,9 +250,7 @@ ngx_eventport_init(ngx_cycle_t *cycle, n
>
> ngx_memzero(&sev, sizeof(struct sigevent));
> sev.sigev_notify = SIGEV_PORT;
> -#if !(NGX_TEST_BUILD_EVENTPORT)
> sev.sigev_value.sival_ptr = &pn;
> -#endif
>
> if (timer_create(CLOCK_REALTIME, &sev, &event_timer) == -1) {
> ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
Looks fine.
--
Maxim Dounin
http://mdounin.ru/
From xeioex at nginx.com Tue Jan 22 15:09:08 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Tue, 22 Jan 2019 15:09:08 +0000
Subject: [njs] Improved setting vm->trace.
Message-ID:
details: https://hg.nginx.org/njs/rev/11cfd1d486f7
branches:
changeset: 735:11cfd1d486f7
user: Dmitry Volyntsev
date: Tue Jan 22 18:08:47 2019 +0300
description:
Improved setting vm->trace.
diffstat:
njs/njs.c | 6 +-----
1 files changed, 1 insertions(+), 5 deletions(-)
diffs (23 lines):
diff -r 0813395557b6 -r 11cfd1d486f7 njs/njs.c
--- a/njs/njs.c Fri Jan 18 15:28:17 2019 +0300
+++ b/njs/njs.c Tue Jan 22 18:08:47 2019 +0300
@@ -335,6 +335,7 @@ njs_vm_clone(njs_vm_t *vm, njs_external_
nvm->mem_cache_pool = nmcp;
nvm->shared = vm->shared;
+ nvm->trace = vm->trace;
nvm->variables_hash = vm->variables_hash;
nvm->values_hash = vm->values_hash;
@@ -444,11 +445,6 @@ njs_vm_init(njs_vm_t *vm)
vm->backtrace = backtrace;
}
- vm->trace.level = NXT_LEVEL_TRACE;
- vm->trace.size = 2048;
- vm->trace.handler = njs_parser_trace_handler;
- vm->trace.data = vm;
-
if (njs_is_null(&vm->retval)) {
vm->retval = njs_value_void;
}
From kahing at cloudflare.com Tue Jan 22 18:20:56 2019
From: kahing at cloudflare.com (Ka-Hing Cheung)
Date: Tue, 22 Jan 2019 10:20:56 -0800
Subject: cache: move open to thread pool
In-Reply-To:
References:
<20180808181653.GX56558@mdounin.ru>
<20180810113946.GG56558@mdounin.ru>
<20180903160903.GI56558@mdounin.ru>
<4ba7414a-0eba-6bd3-5a50-2eca591ac25e@nginx.com>
<2a3577f6-4ad4-aa2d-80a2-7e9b715c070d@nginx.com>
Message-ID:
Hi Maxim and Roman,
We've been running a version of your patches in our test colo for the
past week with no ill effects, with the caveat that it's difficult to
measure performance impacts in our test colo because of varying
traffic. We had to massage the patches a bit because we don't run
vanilla nginx. Also we've only tried with open file cache disabled.
Let me know if you are looking for other feedback.
- Ka-Hing
On Mon, Jan 14, 2019 at 5:53 PM Ka-Hing Cheung wrote:
>
> We didn't get to it last year because of other priorities but this is
> being worked on. We don't use a vanilla nginx so it takes effort to
> integrate your patches. Having a version of this in upstream nginx is
> important to us and to me personally.
>
> On Thu, Jan 10, 2019 at 12:30 AM Maxim Konovalov wrote:
> >
> > So guys, are you really interested in this work beyond shiny
> > marketing blog posts?
> >
> > On 05/12/2018 12:43, Maxim Konovalov wrote:
> > > Hello,
> > >
> > > just a reminder that we are looking for a tester for these patches.
> > >
> > > Thanks,
> > >
> > > Maxim
> > >
> > > On 16/11/2018 12:10, Maxim Konovalov wrote:
> > >> Thanks, Ka-Hing, we'll wait for your feedback.
> > >>
> > >> On 16/11/2018 01:53, Ka-Hing Cheung wrote:
> > >>> Hi,
> > >>>
> > >>> I didn't forget about this. I am pretty swamped at the moment and
> > >>> there's a holiday freeze coming up. Will get to his in December.
> > >>>
> > >>> - Ka-Hing
> > >>>
> > >>> On Thu, Nov 8, 2018 at 6:19 AM Maxim Konovalov wrote:
> > >>>>
> > >>>> Hi Ka-Hing,
> > >>>>
> > >>>> would you mind to test Roman's most recent patches that add
> > >>>> "aio_open" directive?
> > >>>>
> > >>>> http://mailman.nginx.org/pipermail/nginx-devel/2018-November/011538.html
> > >>>>
> > >>>> We are looking for overall performance and stability metrics and
> > >>>> feedback.
> > >>>>
> > >>>> Much appreciated,
> > >>>>
> > >>>> Maxim
> > >>>>
> > >>>> --
> > >>>> Maxim Konovalov
> > >>
> > >>
> > >
> > >
> >
> >
> > --
> > Maxim Konovalov
> > _______________________________________________
> > nginx-devel mailing list
> > nginx-devel at nginx.org
> > http://mailman.nginx.org/mailman/listinfo/nginx-devel
From kahing at cloudflare.com Tue Jan 22 19:34:03 2019
From: kahing at cloudflare.com (Ka-Hing Cheung)
Date: Tue, 22 Jan 2019 11:34:03 -0800
Subject: cache: move open to thread pool
In-Reply-To:
References:
<20180808181653.GX56558@mdounin.ru>
<20180810113946.GG56558@mdounin.ru>
<20180903160903.GI56558@mdounin.ru>
<4ba7414a-0eba-6bd3-5a50-2eca591ac25e@nginx.com>
<2a3577f6-4ad4-aa2d-80a2-7e9b715c070d@nginx.com>
Message-ID:
I spoke too soon, just realized our test colo is running the patches
without aio_open on. Flipping that switch now.
Also, including the patch that we applied on top in addition to the
massaging we did to resolve conflicts. I haven't dug too deep to see
if stock nginx also requires similar changes or they are only
necessary because of our other nginx changes:
--- src/http/ngx_http_file_cache.c
+++ src/http/ngx_http_file_cache.c
@@ -611,6 +611,12 @@ ngx_http_do_file_cache_open(ngx_http_request_t
*r, unsigned ignore_vary)
return NGX_ERROR;
}
+ c->buf = ngx_create_temp_buf(r->pool, c->body_start);
+ if (c->buf == NULL) {
+ return NGX_ERROR;
+ }
+ c->file.fd = NGX_INVALID_FILE;
+
if (!test) {
/*
* Either the request is cacheable but the file doesn't
@@ -1148,6 +1154,7 @@ ngx_http_file_cache_aio_open(ngx_http_request_t
*r, ngx_http_cache_t *c)
ngx_memzero(&r->open_file_info, sizeof(ngx_open_file_info_t));
r->open_file_info.uniq = c->uniq;
+ r->open_file_info.fd = NGX_INVALID_FILE;
r->open_file_info.valid = clcf->open_file_cache_valid;
r->open_file_info.min_uses = clcf->open_file_cache_min_uses;
r->open_file_info.events = clcf->open_file_cache_events;
@@ -1205,11 +1212,6 @@ ngx_http_file_cache_aio_open(ngx_http_request_t
*r, ngx_http_cache_t *c)
c->length = r->open_file_info.size;
c->fs_size = (r->open_file_info.fs_size + cache->bsize - 1) / cache->bsize;
- c->buf = ngx_create_temp_buf(r->pool, c->body_start);
- if (c->buf == NULL) {
- return NGX_ERROR;
- }
-
return NGX_OK;
}
On Tue, Jan 22, 2019 at 10:20 AM Ka-Hing Cheung wrote:
>
> Hi Maxim and Roman,
>
> We've been running a version of your patches in our test colo for the
> past week with no ill effects, with the caveat that it's difficult to
> measure performance impacts in our test colo because of varying
> traffic. We had to massage the patches a bit because we don't run
> vanilla nginx. Also we've only tried with open file cache disabled.
>
> Let me know if you are looking for other feedback.
>
> - Ka-Hing
>
> On Mon, Jan 14, 2019 at 5:53 PM Ka-Hing Cheung wrote:
> >
> > We didn't get to it last year because of other priorities but this is
> > being worked on. We don't use a vanilla nginx so it takes effort to
> > integrate your patches. Having a version of this in upstream nginx is
> > important to us and to me personally.
> >
> > On Thu, Jan 10, 2019 at 12:30 AM Maxim Konovalov wrote:
> > >
> > > So guys, are you really interested in this work beyond shiny
> > > marketing blog posts?
> > >
> > > On 05/12/2018 12:43, Maxim Konovalov wrote:
> > > > Hello,
> > > >
> > > > just a reminder that we are looking for a tester for these patches.
> > > >
> > > > Thanks,
> > > >
> > > > Maxim
> > > >
> > > > On 16/11/2018 12:10, Maxim Konovalov wrote:
> > > >> Thanks, Ka-Hing, we'll wait for your feedback.
> > > >>
> > > >> On 16/11/2018 01:53, Ka-Hing Cheung wrote:
> > > >>> Hi,
> > > >>>
> > > >>> I didn't forget about this. I am pretty swamped at the moment and
> > > >>> there's a holiday freeze coming up. Will get to his in December.
> > > >>>
> > > >>> - Ka-Hing
> > > >>>
> > > >>> On Thu, Nov 8, 2018 at 6:19 AM Maxim Konovalov wrote:
> > > >>>>
> > > >>>> Hi Ka-Hing,
> > > >>>>
> > > >>>> would you mind to test Roman's most recent patches that add
> > > >>>> "aio_open" directive?
> > > >>>>
> > > >>>> http://mailman.nginx.org/pipermail/nginx-devel/2018-November/011538.html
> > > >>>>
> > > >>>> We are looking for overall performance and stability metrics and
> > > >>>> feedback.
> > > >>>>
> > > >>>> Much appreciated,
> > > >>>>
> > > >>>> Maxim
> > > >>>>
> > > >>>> --
> > > >>>> Maxim Konovalov
> > > >>
> > > >>
> > > >
> > > >
> > >
> > >
> > > --
> > > Maxim Konovalov
> > > _______________________________________________
> > > nginx-devel mailing list
> > > nginx-devel at nginx.org
> > > http://mailman.nginx.org/mailman/listinfo/nginx-devel
From maxim at nginx.com Wed Jan 23 12:39:02 2019
From: maxim at nginx.com (Maxim Konovalov)
Date: Wed, 23 Jan 2019 15:39:02 +0300
Subject: cache: move open to thread pool
In-Reply-To:
References:
<20180808181653.GX56558@mdounin.ru>
<20180810113946.GG56558@mdounin.ru>
<20180903160903.GI56558@mdounin.ru>
<4ba7414a-0eba-6bd3-5a50-2eca591ac25e@nginx.com>
<2a3577f6-4ad4-aa2d-80a2-7e9b715c070d@nginx.com>
Message-ID:
Hi Ka-Hing,
Roman told me that the delta is because of your changes.
Thanks for your time on that. Waiting for your testing results.
Maxim
On 22/01/2019 22:34, Ka-Hing Cheung via nginx-devel wrote:
> I spoke too soon, just realized our test colo is running the patches
> without aio_open on. Flipping that switch now.
>
> Also, including the patch that we applied on top in addition to the
> massaging we did to resolve conflicts. I haven't dug too deep to see
> if stock nginx also requires similar changes or they are only
> necessary because of our other nginx changes:
>
[...]
--
Maxim Konovalov
From xeioex at nginx.com Wed Jan 23 17:39:30 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Wed, 23 Jan 2019 17:39:30 +0000
Subject: [njs] Simplified function parsing.
Message-ID:
details: https://hg.nginx.org/njs/rev/72fce46a7669
branches:
changeset: 736:72fce46a7669
user: hongzhidao
date: Wed Jan 23 19:48:19 2019 +0300
description:
Simplified function parsing.
Avoid creating phony parser structures while parsing
function bodies.
diffstat:
njs/njs.c | 15 ++++++-------
njs/njs_generator.c | 25 ++++++++++------------
njs/njs_generator.h | 2 +-
njs/njs_parser.c | 58 +++++++++++++---------------------------------------
njs/njs_parser.h | 5 ++-
5 files changed, 37 insertions(+), 68 deletions(-)
diffs (292 lines):
diff -r 11cfd1d486f7 -r 72fce46a7669 njs/njs.c
--- a/njs/njs.c Tue Jan 22 18:08:47 2019 +0300
+++ b/njs/njs.c Wed Jan 23 19:48:19 2019 +0300
@@ -217,11 +217,10 @@ njs_vm_destroy(njs_vm_t *vm)
nxt_int_t
njs_vm_compile(njs_vm_t *vm, u_char **start, u_char *end)
{
- nxt_int_t ret;
- njs_lexer_t *lexer;
- njs_parser_t *parser, *prev;
- njs_generator_t *generator;
- njs_parser_node_t *node;
+ nxt_int_t ret;
+ njs_lexer_t *lexer;
+ njs_parser_t *parser, *prev;
+ njs_generator_t *generator;
parser = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_parser_t));
if (nxt_slow_path(parser == NULL)) {
@@ -252,8 +251,8 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
vm->retval = njs_value_void;
- node = njs_parser(vm, parser, prev);
- if (nxt_slow_path(node == NULL)) {
+ ret = njs_parser(vm, parser, prev);
+ if (nxt_slow_path(ret != NXT_OK)) {
goto fail;
}
@@ -279,7 +278,7 @@ njs_vm_compile(njs_vm_t *vm, u_char **st
nxt_memzero(generator, sizeof(njs_generator_t));
- ret = njs_generate_scope(vm, generator, node);
+ ret = njs_generate_scope(vm, generator, parser->scope);
if (nxt_slow_path(ret != NXT_OK)) {
goto fail;
}
diff -r 11cfd1d486f7 -r 72fce46a7669 njs/njs_generator.c
--- a/njs/njs_generator.c Tue Jan 22 18:08:47 2019 +0300
+++ b/njs/njs_generator.c Wed Jan 23 19:48:19 2019 +0300
@@ -2303,7 +2303,7 @@ njs_generate_function_scope(njs_vm_t *vm
node = node->right;
- ret = njs_generate_scope(vm, generator, node);
+ ret = njs_generate_scope(vm, generator, node->scope);
if (nxt_fast_path(ret == NXT_OK)) {
size = 0;
@@ -2334,18 +2334,15 @@ njs_generate_function_scope(njs_vm_t *vm
nxt_int_t
njs_generate_scope(njs_vm_t *vm, njs_generator_t *generator,
- njs_parser_node_t *node)
+ njs_parser_scope_t *scope)
{
- u_char *p;
- size_t size;
- uintptr_t scope_size;
- nxt_int_t ret;
- nxt_uint_t n;
- njs_value_t *value;
- njs_vm_code_t *code;
- njs_parser_scope_t *scope;
-
- scope = node->scope;
+ u_char *p;
+ size_t size;
+ uintptr_t scope_size;
+ nxt_int_t ret;
+ nxt_uint_t n;
+ njs_value_t *value;
+ njs_vm_code_t *code;
generator->code_size = 128;
@@ -2357,12 +2354,12 @@ njs_generate_scope(njs_vm_t *vm, njs_gen
generator->code_start = p;
generator->code_end = p;
- ret = njs_generate_argument_closures(vm, generator, node);
+ ret = njs_generate_argument_closures(vm, generator, scope->node);
if (nxt_slow_path(ret != NXT_OK)) {
return NXT_ERROR;
}
- if (nxt_slow_path(njs_generator(vm, generator, node) != NXT_OK)) {
+ if (nxt_slow_path(njs_generator(vm, generator, scope->node) != NXT_OK)) {
return NXT_ERROR;
}
diff -r 11cfd1d486f7 -r 72fce46a7669 njs/njs_generator.h
--- a/njs/njs_generator.h Tue Jan 22 18:08:47 2019 +0300
+++ b/njs/njs_generator.h Wed Jan 23 19:48:19 2019 +0300
@@ -29,7 +29,7 @@ struct njs_generator_s {
nxt_int_t njs_generate_scope(njs_vm_t *vm, njs_generator_t *generator,
- njs_parser_node_t *node);
+ njs_parser_scope_t *scope);
#endif /* _NJS_GENERATOR_H_INCLUDED_ */
diff -r 11cfd1d486f7 -r 72fce46a7669 njs/njs_parser.c
--- a/njs/njs_parser.c Tue Jan 22 18:08:47 2019 +0300
+++ b/njs/njs_parser.c Wed Jan 23 19:48:19 2019 +0300
@@ -23,8 +23,6 @@ static njs_token_t njs_parser_block(njs_
njs_parser_t *parser, njs_token_t token);
static njs_token_t njs_parser_function_declaration(njs_vm_t *vm,
njs_parser_t *parser);
-static njs_parser_t *njs_parser_function_create(njs_vm_t *vm,
- njs_parser_t *parent);
static njs_token_t njs_parser_function_lambda(njs_vm_t *vm,
njs_parser_t *parser, njs_function_lambda_t *lambda, njs_token_t token);
static njs_token_t njs_parser_return_statement(njs_vm_t *vm,
@@ -68,7 +66,7 @@ static njs_token_t njs_parser_unexpected
njs_parser_t *parser, njs_token_t token);
-njs_parser_node_t *
+nxt_int_t
njs_parser(njs_vm_t *vm, njs_parser_t *parser, njs_parser_t *prev)
{
njs_ret_t ret;
@@ -81,7 +79,7 @@ njs_parser(njs_vm_t *vm, njs_parser_t *p
ret = njs_parser_scope_begin(vm, parser, NJS_SCOPE_GLOBAL);
if (nxt_slow_path(ret != NXT_OK)) {
- return NULL;
+ return NXT_ERROR;
}
if (prev != NULL) {
@@ -111,7 +109,7 @@ njs_parser(njs_vm_t *vm, njs_parser_t *p
ret = nxt_lvlhsh_insert(variables, &lhq);
if (nxt_slow_path(ret != NXT_OK)) {
- return NULL;
+ return NXT_ERROR;
}
}
}
@@ -122,7 +120,7 @@ njs_parser(njs_vm_t *vm, njs_parser_t *p
token = njs_parser_statement_chain(vm, parser, token);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return NULL;
+ return NXT_ERROR;
}
if (token == NJS_TOKEN_CLOSE_BRACE && vm->options.trailer) {
@@ -138,14 +136,16 @@ njs_parser(njs_vm_t *vm, njs_parser_t *p
node = njs_parser_node_alloc(vm);
if (nxt_slow_path(node == NULL)) {
- return NULL;
+ return NXT_ERROR;
}
}
node->token = NJS_TOKEN_END;
node->scope = parser->scope;
- return node;
+ parser->scope->node = node;
+
+ return NXT_OK;
}
@@ -545,15 +545,8 @@ njs_parser_function_declaration(njs_vm_t
var->value.type = NJS_FUNCTION;
var->value.data.truth = 1;
- parser = njs_parser_function_create(vm, parser);
- if (nxt_slow_path(parser == NULL)) {
- return NJS_TOKEN_ERROR;
- }
-
token = njs_parser_function_lambda(vm, parser, function->u.lambda, token);
- vm->parser = parser->parent;
-
return token;
}
@@ -578,11 +571,6 @@ njs_parser_function_expression(njs_vm_t
node->scope = parser->scope;
parser->node = node;
- parser = njs_parser_function_create(vm, parser);
- if (nxt_slow_path(parser == NULL)) {
- return NJS_TOKEN_ERROR;
- }
-
token = njs_parser_token(parser);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
@@ -634,31 +622,10 @@ njs_parser_function_expression(njs_vm_t
njs_parser_scope_end(vm, parser);
- vm->parser = parser->parent;
-
return token;
}
-static njs_parser_t *
-njs_parser_function_create(njs_vm_t *vm, njs_parser_t *parent)
-{
- njs_parser_t *parser;
-
- parser = nxt_mem_cache_zalloc(vm->mem_cache_pool, sizeof(njs_parser_t));
- if (nxt_slow_path(parser == NULL)) {
- return NULL;
- }
-
- parser->parent = parent;
- parser->scope = parent->scope;
- parser->lexer = parent->lexer;
- vm->parser = parser;
-
- return parser;
-}
-
-
static njs_token_t
njs_parser_function_lambda(njs_vm_t *vm, njs_parser_t *parser,
njs_function_lambda_t *lambda, njs_token_t token)
@@ -666,7 +633,7 @@ njs_parser_function_lambda(njs_vm_t *vm,
njs_ret_t ret;
njs_index_t index;
njs_variable_t *arg;
- njs_parser_node_t *node, *body, *last;
+ njs_parser_node_t *node, *body, *last, *parent;
ret = njs_parser_scope_begin(vm, parser, NJS_SCOPE_FUNCTION);
if (nxt_slow_path(ret != NXT_OK)) {
@@ -744,6 +711,7 @@ njs_parser_function_lambda(njs_vm_t *vm,
return token;
}
+ parent = parser->node;
parser->node = NULL;
while (token != NJS_TOKEN_CLOSE_BRACE) {
@@ -796,8 +764,12 @@ njs_parser_function_lambda(njs_vm_t *vm,
node->right->token = NJS_TOKEN_RETURN;
}
- parser->parent->node->right = parser->node;
+ parent->right = parser->node;
+
parser->node->scope = parser->scope;
+ parser->scope->node = parser->node;
+
+ parser->node = parent;
njs_parser_scope_end(vm, parser);
diff -r 11cfd1d486f7 -r 72fce46a7669 njs/njs_parser.h
--- a/njs/njs_parser.h Tue Jan 22 18:08:47 2019 +0300
+++ b/njs/njs_parser.h Wed Jan 23 19:48:19 2019 +0300
@@ -232,6 +232,8 @@ typedef struct {
struct njs_parser_scope_s {
+ njs_parser_node_t *node;
+
nxt_queue_link_t link;
nxt_queue_t nested;
@@ -289,7 +291,6 @@ struct njs_parser_s {
njs_lexer_t *lexer;
njs_parser_node_t *node;
njs_parser_scope_t *scope;
- njs_parser_t *parent;
};
@@ -308,7 +309,7 @@ njs_token_t njs_lexer_keyword(njs_lexer_
njs_value_t *njs_parser_external(njs_vm_t *vm, njs_parser_t *parser);
-njs_parser_node_t *njs_parser(njs_vm_t *vm, njs_parser_t *parser,
+nxt_int_t njs_parser(njs_vm_t *vm, njs_parser_t *parser,
njs_parser_t *prev);
njs_token_t njs_parser_arguments(njs_vm_t *vm, njs_parser_t *parser,
njs_parser_node_t *parent);
From sepherosa at gmail.com Thu Jan 24 02:04:09 2019
From: sepherosa at gmail.com (Sepherosa Ziehau)
Date: Thu, 24 Jan 2019 10:04:09 +0800
Subject: aio/unix: Use signal.sival which is standard
In-Reply-To: <80C7E6D7-4FBE-471B-A53D-D0FB777EA88E@nginx.com>
References:
<47C75FB8-1DB2-4864-B5DA-13D915E73592@nginx.com>
<20190117132251.GI99070@mdounin.ru>
<76EB7D89-8048-4CB5-AB87-A94C2C52F808@nginx.com>
<80C7E6D7-4FBE-471B-A53D-D0FB777EA88E@nginx.com>
Message-ID:
On Fri, Jan 18, 2019 at 6:22 PM Sergey Kandaurov wrote:
>
>
>
> > On 18 Jan 2019, at 10:39, Sepherosa Ziehau wrote:
> >
> > Hi,
> >
> >> diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h
> >> --- a/src/os/unix/ngx_freebsd_config.h
> >> +++ b/src/os/unix/ngx_freebsd_config.h
> >> @@ -91,6 +91,10 @@
> >> #if (NGX_HAVE_FILE_AIO)
> >> #include
> >> typedef struct aiocb ngx_aiocb_t;
> >> +
> >> +#if (__FreeBSD_version < 700005 && !defined __DragonFly__)
> >> +#define sival_ptr sigval_ptr
> >> +#endif
> >> #endif
> >
> > Will the following code be more straightforward?
> > #if defined(__FreeBSD__) && (__FreeBSD_version < 700005)
> > #define sival_ptr sigval_ptr
> > #endif
>
> This won't work. __FreeBSD__ and__FreeBSD_version
> are defined for DragonFly in src/core/ngx_config.h.
Aha, I see. Thank you.
--
Tomorrow Will Never Die
From sepherosa at gmail.com Thu Jan 24 02:07:57 2019
From: sepherosa at gmail.com (Sepherosa Ziehau)
Date: Thu, 24 Jan 2019 10:07:57 +0800
Subject: aio/unix: Use signal.sival which is standard
In-Reply-To: <20190122145429.GE1877@mdounin.ru>
References:
<47C75FB8-1DB2-4864-B5DA-13D915E73592@nginx.com>
<20190117132251.GI99070@mdounin.ru>
<76EB7D89-8048-4CB5-AB87-A94C2C52F808@nginx.com>
<20190122145429.GE1877@mdounin.ru>
Message-ID:
On Tue, Jan 22, 2019 at 10:54 PM Maxim Dounin wrote:
> This needs to be extended with some background information -
> notably why it used to be sigval_ptr, and why to switch to
> sival_ptr.
I am not sure why it used to be sigval_ptr; seems to be a miss name in
FreeBSD. And the code seems to assume having KQUEUE == having
sigval_ptr.
As about why the switching:
- It's POSIX standard.
- It was noticed recently in DragonFly, since we removed this compat
field (sigval_ptr), since after scanning the source code in ports
system, nginx seems to be the only one using sigval_ptr.
Thanks,
sephe
>
> >
> > diff --git a/src/os/unix/ngx_file_aio_read.c b/src/os/unix/ngx_file_aio_read.c
> > --- a/src/os/unix/ngx_file_aio_read.c
> > +++ b/src/os/unix/ngx_file_aio_read.c
> > @@ -110,7 +110,7 @@ ngx_file_aio_read(ngx_file_t *file, u_ch
> > #if (NGX_HAVE_KQUEUE)
> > aio->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
> > aio->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
> > - aio->aiocb.aio_sigevent.sigev_value.sigval_ptr = ev;
> > + aio->aiocb.aio_sigevent.sigev_value.sival_ptr = ev;
> > #endif
> > ev->handler = ngx_file_aio_event_handler;
> >
> > diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h
> > --- a/src/os/unix/ngx_freebsd_config.h
> > +++ b/src/os/unix/ngx_freebsd_config.h
> > @@ -91,6 +91,10 @@
> > #if (NGX_HAVE_FILE_AIO)
> > #include
> > typedef struct aiocb ngx_aiocb_t;
> > +
> > +#if (__FreeBSD_version < 700005 && !defined __DragonFly__)
> > +#define sival_ptr sigval_ptr
> > +#endif
> > #endif
> >
> >
>
> Minor style nits:
>
> diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h
> --- a/src/os/unix/ngx_freebsd_config.h
> +++ b/src/os/unix/ngx_freebsd_config.h
> @@ -89,12 +89,14 @@
>
>
> #if (NGX_HAVE_FILE_AIO)
> +
> #include
> typedef struct aiocb ngx_aiocb_t;
>
> #if (__FreeBSD_version < 700005 && !defined __DragonFly__)
> -#define sival_ptr sigval_ptr
> +#define sival_ptr sigval_ptr
> #endif
> +
> #endif
>
>
> > # HG changeset patch
> > # User Sergey Kandaurov
> > # Date 1547736673 0
> > # Thu Jan 17 14:51:13 2019 +0000
> > # Node ID c66911fc9924a60bb5d691ca00bc2fb1c3032866
> > # Parent baab2b35e8cc79cfdf9924d1752348e97c1da13e
> > Removed --test-build-eventport workaround for old FreeBSD versions.
> >
> > diff --git a/src/event/modules/ngx_eventport_module.c b/src/event/modules/ngx_eventport_module.c
> > --- a/src/event/modules/ngx_eventport_module.c
> > +++ b/src/event/modules/ngx_eventport_module.c
> > @@ -250,9 +250,7 @@ ngx_eventport_init(ngx_cycle_t *cycle, n
> >
> > ngx_memzero(&sev, sizeof(struct sigevent));
> > sev.sigev_notify = SIGEV_PORT;
> > -#if !(NGX_TEST_BUILD_EVENTPORT)
> > sev.sigev_value.sival_ptr = &pn;
> > -#endif
> >
> > if (timer_create(CLOCK_REALTIME, &sev, &event_timer) == -1) {
> > ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
>
> Looks fine.
>
> --
> Maxim Dounin
> http://mdounin.ru/
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
--
Tomorrow Will Never Die
From mdounin at mdounin.ru Thu Jan 24 14:59:14 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Thu, 24 Jan 2019 17:59:14 +0300
Subject: aio/unix: Use signal.sival which is standard
In-Reply-To:
References:
<47C75FB8-1DB2-4864-B5DA-13D915E73592@nginx.com>
<20190117132251.GI99070@mdounin.ru>
<76EB7D89-8048-4CB5-AB87-A94C2C52F808@nginx.com>
<20190122145429.GE1877@mdounin.ru>
Message-ID: <20190124145914.GN1877@mdounin.ru>
Hello!
On Thu, Jan 24, 2019 at 10:07:57AM +0800, Sepherosa Ziehau wrote:
> On Tue, Jan 22, 2019 at 10:54 PM Maxim Dounin wrote:
> > This needs to be extended with some background information -
> > notably why it used to be sigval_ptr, and why to switch to
> > sival_ptr.
>
> I am not sure why it used to be sigval_ptr; seems to be a miss name in
> FreeBSD. And the code seems to assume having KQUEUE == having sigval_ptr.
>
> As about why the switching:
> - It's POSIX standard.
> - It was noticed recently in DragonFly, since we removed this compat
> field (sigval_ptr), since after scanning the source code in ports
> system, nginx seems to be the only one using sigval_ptr.
Yes, Sergey have details on hand. It was renamed (likely by
accident) in 1999 (FreeBSD 4.0) when introducing SA_SIGINFO
support[1]. Standard-complaint name was restored in 2005 (first
released in FreeBSD 7.0 in 2008), retaining compatibility with
previous versions[2][3]. Similar changes were committed in
DragonFly in 2009[4].
Since initial AIO support in nginx was introduced in 2003[5], it
used the only name available at the moment.
Switching to a standard name now is fine, especially giving that
we can easily retain compatibility with previous versions.
But at least some of these details need to be preserved in the
commit log, and that's what I was asking Sergey about.
[1] https://github.com/freebsd/freebsd/commit/53573bf465904188986e8c982e8019835628d6b2
[2] https://github.com/freebsd/freebsd/commit/ae161ac2394e00bb3afca0667a13243d7963dfe2
[3] https://github.com/freebsd/freebsd/commit/54f35995c2ce65f23beb667de4ccf3d68139a81a
[4] https://gitweb.dragonflybsd.org/dragonfly.git/commit/36934016eeaca3abd418acb1c68bd391d3b54aa7
[5] http://hg.nginx.org/nginx/rev/738fe44c70d5
--
Maxim Dounin
http://mdounin.ru/
From teward at thomas-ward.net Thu Jan 24 15:23:01 2019
From: teward at thomas-ward.net (Thomas Ward)
Date: Thu, 24 Jan 2019 10:23:01 -0500
Subject: PCRE2 support?
In-Reply-To:
References: <20180918121231.843FC2C50D50@mail.nginx.com>
<20180918155518.GQ56558@mdounin.ru>
Message-ID: <0522327a-8b2c-f066-ddd6-392207ec6c1d@thomas-ward.net>
It's been several more months, but now I need to ask what distributions
you are 'supporting' here, Maxim and nginx team.
PCRE2 is in Debian, Ubuntu, CentOS, Fedora, and others.? That covers a
large portion of the major distributions at play.
This has once again popped on my radar in Ubuntu as we are trying to
move pcre3 out of Main, and rely on pcre2.? NGINX is one of the few
packages that hasn't had any changes to it to make it PCRE2-supportable.
I also agree that Exim should not be the basis of support.
Is it possible to revisit this decision, and determine whether it is
possible to support PCRE2 as it is now 2019 and many things seem to be
switching to pcre2?? Otherwise, we have to either
(1) Strip out PCRE support entirely in NGINX in Ubuntu, which would
break most if not all regex functionality.
(2) No longer consider nginx supported officially and drop it to
community-only support (which means I will be once again doing all the
work in Ubuntu to patch it, though this isn't new for me).
I would like to ask that this be re-discussed and revisited since PCRE2
is far from 'new' and many things're switching to it, as well as it
being present in multiple major distributions now.
Thomas
On 9/19/18 3:19 AM, Mark Mielke wrote:
> On Tue, Sep 18, 2018 at 11:55 AM Maxim Dounin > wrote:
>
> On Tue, Sep 18, 2018 at 08:12:20AM -0400, Thomas Ward wrote:
> > Downstream in Ubuntu, it has been proposed to demote pcre3 and
> > use pcre2 instead as it is newer.
> > https://trac.nginx.org/nginx/ticket/720 shows it was marked 4
> > years ago that NGINX does not support pcre2.? Are there any
> > plans to use pcre2 instead of pcre3?
> There are no immediate plans.
> When we last checked, there were no problems with PCRE, but PCRE2
> wasn't available in most distributions we support, making the
> switch mostly meaningless.
>
>
> I think there have been changes since then. PCRE2 was new in 2015, but
> isn't new in 2018.
>
> RHEL 7 (and clones) include libpcre2. I think this is a pretty wide
> set of machines right here. I believe Ubuntu 16.04 LTS has libpcre2
> which is another wide set. Fedora has had it for a while now. I think
> that unless you go to older releases, all major distributions should
> have PCRE2 by now.
>
> I build haproxy with PCRE2 support.
>
> One that was interesting to me, is that Git recently (April, 2018?)
> switched to building with PCRE2 by default when "USE_LIBPCRE=Yes" was
> specified:
>
> https://github.com/git/git/commit/cac5351363c5713248b8494e1e58e282c0a5bde7
>
> I'm not sure about meaningless from a functionality perspective. All
> new features are going into PCRE2. PCRE is a stable branched with only
> bug fixes and security problems fixed. The newest features, including
> performance improvements, are all in PCRE2. I believe the reason it is
> "PCRE2-10" instead of "PCRE-10", is because of API changes, and the
> opportunity to improve or fix previous API decisions. This then
> becomes the basis for all future development free of the PCRE API
> shackles.
>
> ?
>
>
> Also, it looks like PCRE2 is still not supported even by Exim,
> which is the parent project of PCRE and PCRE2:
>
> https://bugs.exim.org/show_bug.cgi?id=1878
>
>
> I don't think Exim should be the measure:
>
> "PCRE was originally written for the?Exim MTA ,
> but is now used by many high-profile open source projects,
> including?Apache ,?PHP
> ,?KDE ,?Postfix
> , and?Nmap . PCRE has also
> found its way into some well known commercial products, like?Apple
> Safari . Some other interesting
> projects using PCRE include?Chicken
> ,?Ferite
> ,?Onyx
> ,?Hypermail
> ,?Leafnode
> ,?Askemos
> ,?Wenlin , and?8th
> ."
>
> This list is also far from complete. PCRE and PCRE2 are widely used,
> and PCRE2 is where all current improvement is occurring. Anybody
> waiting for Exim, will probably be among the very last to switch.
>
>
> As such, adding PCRE2 support to nginx looks premature.
>
>
>
> Before writing the above, I was debating with myself about when the
> right time to add support for a new component release is. For some
> projects and some components, it will be more important than others.
> For example, OpenSSL 1.1.1 with TLSv1.3 support might be considered
> premature for some projects to support, and yet Nginx supports this
> newly released version long before OpenSSL 1.1.1 is readily available
> in a majority of distributions that you support. I think in this case,
> OpenSSL 1.1.1 is of strategic importance to Nginx, and this ensured it
> was on the roadmap. (However, it still seems to be missing an ability
> to configure the cipher suite... :-) )
>
> I don't know if PCRE2 belongs on this roadmap. I think there have been
> significant improvements with the JIT compilation that could prove
> useful for higher performance evaluation of regular expressions with
> Nginx, but I personally don't have this requirement, so if after
> considering all of the above - you still felt it was premature, I
> wouldn't raise any concern personally. I just want to make sure this
> is an informed position. :-)
>
> --
> Mark Mielke >
>
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
From mdounin at mdounin.ru Thu Jan 24 18:21:22 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Thu, 24 Jan 2019 21:21:22 +0300
Subject: PCRE2 support?
In-Reply-To: <0522327a-8b2c-f066-ddd6-392207ec6c1d@thomas-ward.net>
References: <20180918121231.843FC2C50D50@mail.nginx.com>
<20180918155518.GQ56558@mdounin.ru>
<0522327a-8b2c-f066-ddd6-392207ec6c1d@thomas-ward.net>
Message-ID: <20190124182121.GP1877@mdounin.ru>
Hello!
On Thu, Jan 24, 2019 at 10:23:01AM -0500, Thomas Ward wrote:
> It's been several more months, but now I need to ask what distributions
> you are 'supporting' here, Maxim and nginx team.
>
> PCRE2 is in Debian, Ubuntu, CentOS, Fedora, and others.? That covers a
> large portion of the major distributions at play.
List of the Linux distributions most interesting for us can be
found here:
http://nginx.org/en/linux_packages.html
It looks like most have PCRE2 now. Though obviously enough, there
are at least some where there are no PCRE2, including Ubuntu 14.04
which is expected to be supported till April 2019, Debian 8, which
is to be supported till 2020, and CentOS 6, which is to be
supported till 2020 as well.
> This has once again popped on my radar in Ubuntu as we are trying to
> move pcre3 out of Main, and rely on pcre2.? NGINX is one of the few
> packages that hasn't had any changes to it to make it PCRE2-supportable.
So this is going to be the first real reason to actually support
PCRE2. Patches are welcome.
> I also agree that Exim should not be the basis of support.
Well, this depends on your point of view. If a project which
actually developed the library fails to introduce support to the
new version of the library - for an external observer this
suggests that there is something wrong with the new version.
[...]
--
Maxim Dounin
http://mdounin.ru/
From pgnet.dev at gmail.com Thu Jan 24 18:47:48 2019
From: pgnet.dev at gmail.com (PGNet Dev)
Date: Thu, 24 Jan 2019 10:47:48 -0800
Subject: PCRE2 support?
In-Reply-To: <20190124182121.GP1877@mdounin.ru>
References: <20180918121231.843FC2C50D50@mail.nginx.com>
<20180918155518.GQ56558@mdounin.ru>
<0522327a-8b2c-f066-ddd6-392207ec6c1d@thomas-ward.net>
<20190124182121.GP1877@mdounin.ru>
Message-ID: <5f5a8d73-77b5-bf62-d963-5e2927aa72e1@gmail.com>
> Well, this depends on your point of view. If a project which
> actually developed the library fails to introduce support to the
> new version of the library - for an external observer this
> suggests that there is something wrong with the new version.
FUD 'suggestions' simply aren't needed.
The Exim project didn't develop the pcre2 library ... Philip Hazel did
(https://www.pcre.org/current/doc/html/pcre2.html#SEC4), as a separate
project.
Exim's last (? something newer out there?) rationale for not adopting it
was simply,
https://bugs.exim.org/show_bug.cgi?id=1878
"The original PCRE support is not broken.
If it is going to go away, then adding PCRE2 support becomes much more
important, but I've seen nobody saying that yet."
Also of note,
https://pcre.org/pcre.txt
"The old libraries (now called PCRE1) are still being maintained for bug
fixes, but there will be no new development. New projects are
advised to use the new PCRE2 libraries."
From mdounin at mdounin.ru Thu Jan 24 20:16:17 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Thu, 24 Jan 2019 20:16:17 +0000
Subject: [nginx] Events: fixed copying of old events in poll init.
Message-ID:
details: https://hg.nginx.org/nginx/rev/e0e636ab10be
branches:
changeset: 7442:e0e636ab10be
user: Maxim Dounin
date: Thu Jan 24 21:50:37 2019 +0300
description:
Events: fixed copying of old events in poll init.
Previously, the code incorrectly assumed "ngx_event_t *" elements
instead of "struct pollfd".
This is mostly cosmetic change, as this code is never called now.
diffstat:
src/event/modules/ngx_poll_module.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diffs (12 lines):
diff --git a/src/event/modules/ngx_poll_module.c b/src/event/modules/ngx_poll_module.c
--- a/src/event/modules/ngx_poll_module.c
+++ b/src/event/modules/ngx_poll_module.c
@@ -84,7 +84,7 @@ ngx_poll_init(ngx_cycle_t *cycle, ngx_ms
}
if (event_list) {
- ngx_memcpy(list, event_list, sizeof(ngx_event_t *) * nevents);
+ ngx_memcpy(list, event_list, sizeof(struct pollfd) * nevents);
ngx_free(event_list);
}
From mdounin at mdounin.ru Thu Jan 24 20:16:18 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Thu, 24 Jan 2019 20:16:18 +0000
Subject: [nginx] Win32: properly enabled select on Windows.
Message-ID:
details: https://hg.nginx.org/nginx/rev/f3ff79ae31d9
branches:
changeset: 7443:f3ff79ae31d9
user: Maxim Dounin
date: Thu Jan 24 21:51:00 2019 +0300
description:
Win32: properly enabled select on Windows.
Previously, select was compiled in by default, but the NGX_HAVE_SELECT
macro was not set, resulting in iocp being used by default unless
the "--with-select_module" configure option was explicitly specified.
Since the iocp module is not finished and does not work properly, this
effectively meant that the "--with-select_module" option was mandatory.
With the change NGX_HAVE_SELECT is properly set, making "--with-select_module"
optional. Accordingly, it is removed from misc/GNUmakefile win32 target.
diffstat:
auto/os/win32 | 1 +
misc/GNUmakefile | 1 -
2 files changed, 1 insertions(+), 1 deletions(-)
diffs (22 lines):
diff --git a/auto/os/win32 b/auto/os/win32
--- a/auto/os/win32
+++ b/auto/os/win32
@@ -34,6 +34,7 @@ EVENT_MODULES="$EVENT_MODULES $IOCP_MODU
EVENT_FOUND=YES
if [ $EVENT_SELECT = NO ]; then
+ have=NGX_HAVE_SELECT . auto/have
CORE_SRCS="$CORE_SRCS $SELECT_SRCS"
EVENT_MODULES="$EVENT_MODULES $SELECT_MODULE"
fi
diff --git a/misc/GNUmakefile b/misc/GNUmakefile
--- a/misc/GNUmakefile
+++ b/misc/GNUmakefile
@@ -65,7 +65,6 @@ win32:
--with-cc-opt=-DFD_SETSIZE=1024 \
--with-pcre=$(OBJS)/lib/$(PCRE) \
--with-zlib=$(OBJS)/lib/$(ZLIB) \
- --with-select_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
From mdounin at mdounin.ru Thu Jan 24 20:16:20 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Thu, 24 Jan 2019 20:16:20 +0000
Subject: [nginx] Win32: added WSAPoll() support.
Message-ID:
details: https://hg.nginx.org/nginx/rev/4089b3d2cb59
branches:
changeset: 7444:4089b3d2cb59
user: Maxim Dounin
date: Thu Jan 24 21:51:21 2019 +0300
description:
Win32: added WSAPoll() support.
WSAPoll() is only available with Windows Vista and newer (and only
available during compilation if _WIN32_WINNT >= 0x0600). To make
sure the code works with Windows XP, we do not redefine _WIN32_WINNT,
but instead load WSAPoll() dynamically if it is not available during
compilation.
Also, sockets are not guaranteed to be small integers on Windows.
So an index array is used instead of NGX_USE_FD_EVENT to map
events to connections.
diffstat:
auto/os/win32 | 1 +
auto/sources | 1 +
src/event/modules/ngx_win32_poll_module.c | 74 +++++++++++++++++++-----------
src/os/win32/ngx_socket.h | 43 ++++++++++++++++++
src/os/win32/ngx_win32_init.c | 32 +++++++++++++
5 files changed, 124 insertions(+), 27 deletions(-)
diffs (322 lines):
diff --git a/auto/os/win32 b/auto/os/win32
--- a/auto/os/win32
+++ b/auto/os/win32
@@ -11,6 +11,7 @@ CORE_SRCS="$WIN32_SRCS $IOCP_SRCS"
OS_CONFIG="$WIN32_CONFIG"
NGX_ICONS="$NGX_WIN32_ICONS"
SELECT_SRCS=$WIN32_SELECT_SRCS
+POLL_SRCS=$WIN32_POLL_SRCS
ngx_pic_opt=
ngx_binext=".exe"
diff --git a/auto/sources b/auto/sources
--- a/auto/sources
+++ b/auto/sources
@@ -106,6 +106,7 @@ WIN32_SELECT_SRCS=src/event/modules/ngx_
POLL_MODULE=ngx_poll_module
POLL_SRCS=src/event/modules/ngx_poll_module.c
+WIN32_POLL_SRCS=src/event/modules/ngx_win32_poll_module.c
KQUEUE_MODULE=ngx_kqueue_module
KQUEUE_SRCS=src/event/modules/ngx_kqueue_module.c
diff --git a/src/event/modules/ngx_poll_module.c b/src/event/modules/ngx_win32_poll_module.c
copy from src/event/modules/ngx_poll_module.c
copy to src/event/modules/ngx_win32_poll_module.c
--- a/src/event/modules/ngx_poll_module.c
+++ b/src/event/modules/ngx_win32_poll_module.c
@@ -1,6 +1,7 @@
/*
* Copyright (C) Igor Sysoev
+ * Copyright (C) Maxim Dounin
* Copyright (C) Nginx, Inc.
*/
@@ -21,8 +22,9 @@ static ngx_int_t ngx_poll_process_events
static char *ngx_poll_init_conf(ngx_cycle_t *cycle, void *conf);
-static struct pollfd *event_list;
-static ngx_uint_t nevents;
+static struct pollfd *event_list;
+static ngx_connection_t **event_index;
+static ngx_uint_t nevents;
static ngx_str_t poll_name = ngx_string("poll");
@@ -67,7 +69,8 @@ ngx_module_t ngx_poll_module = {
static ngx_int_t
ngx_poll_init(ngx_cycle_t *cycle, ngx_msec_t timer)
{
- struct pollfd *list;
+ struct pollfd *list;
+ ngx_connection_t **index;
if (event_list == NULL) {
nevents = 0;
@@ -89,13 +92,27 @@ ngx_poll_init(ngx_cycle_t *cycle, ngx_ms
}
event_list = list;
+
+ index = ngx_alloc(sizeof(ngx_connection_t *) * cycle->connection_n,
+ cycle->log);
+ if (index == NULL) {
+ return NGX_ERROR;
+ }
+
+ if (event_index) {
+ ngx_memcpy(index, event_index,
+ sizeof(ngx_connection_t *) * nevents);
+ ngx_free(event_index);
+ }
+
+ event_index = index;
}
ngx_io = ngx_os_io;
ngx_event_actions = ngx_poll_module_ctx.actions;
- ngx_event_flags = NGX_USE_LEVEL_EVENT|NGX_USE_FD_EVENT;
+ ngx_event_flags = NGX_USE_LEVEL_EVENT;
return NGX_OK;
}
@@ -105,8 +122,10 @@ static void
ngx_poll_done(ngx_cycle_t *cycle)
{
ngx_free(event_list);
+ ngx_free(event_index);
event_list = NULL;
+ event_index = NULL;
}
@@ -143,10 +162,13 @@ ngx_poll_add_event(ngx_event_t *ev, ngx_
"poll add event: fd:%d ev:%i", c->fd, event);
if (e == NULL || e->index == NGX_INVALID_INDEX) {
+
event_list[nevents].fd = c->fd;
event_list[nevents].events = (short) event;
event_list[nevents].revents = 0;
+ event_index[nevents] = c;
+
ev->index = nevents;
nevents++;
@@ -204,10 +226,11 @@ ngx_poll_del_event(ngx_event_t *ev, ngx_
"index: copy event %ui to %i", nevents, ev->index);
event_list[ev->index] = event_list[nevents];
+ event_index[ev->index] = event_index[nevents];
- c = ngx_cycle->files[event_list[nevents].fd];
+ c = event_index[ev->index];
- if (c->fd == -1) {
+ if (c->fd == (ngx_socket_t) -1) {
ngx_log_error(NGX_LOG_ALERT, ev->log, 0,
"unexpected last event");
@@ -240,7 +263,7 @@ ngx_poll_process_events(ngx_cycle_t *cyc
{
int ready, revents;
ngx_err_t err;
- ngx_uint_t i, found, level;
+ ngx_uint_t i, found;
ngx_event_t *ev;
ngx_queue_t *queue;
ngx_connection_t *c;
@@ -259,7 +282,7 @@ ngx_poll_process_events(ngx_cycle_t *cyc
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "poll timer: %M", timer);
- ready = poll(event_list, (u_int) nevents, (int) timer);
+ ready = WSAPoll(event_list, (u_int) nevents, (int) timer);
err = (ready == -1) ? ngx_errno : 0;
@@ -271,20 +294,7 @@ ngx_poll_process_events(ngx_cycle_t *cyc
"poll ready %d of %ui", ready, nevents);
if (err) {
- if (err == NGX_EINTR) {
-
- if (ngx_event_timer_alarm) {
- ngx_event_timer_alarm = 0;
- return NGX_OK;
- }
-
- level = NGX_LOG_INFO;
-
- } else {
- level = NGX_LOG_ALERT;
- }
-
- ngx_log_error(level, cycle->log, err, "poll() failed");
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, err, "WSAPoll() failed");
return NGX_ERROR;
}
@@ -294,7 +304,7 @@ ngx_poll_process_events(ngx_cycle_t *cyc
}
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0,
- "poll() returned no events without timeout");
+ "WSAPoll() returned no events without timeout");
return NGX_ERROR;
}
@@ -326,7 +336,7 @@ ngx_poll_process_events(ngx_cycle_t *cyc
event_list[i].fd, event_list[i].events, revents);
}
- if (event_list[i].fd == -1) {
+ if (event_list[i].fd == (ngx_socket_t) -1) {
/*
* the disabled event, a workaround for our possible bug,
* see the comment below
@@ -334,9 +344,9 @@ ngx_poll_process_events(ngx_cycle_t *cyc
continue;
}
- c = ngx_cycle->files[event_list[i].fd];
+ c = event_index[i];
- if (c->fd == -1) {
+ if (c->fd == (ngx_socket_t) -1) {
ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "unexpected event");
/*
@@ -347,7 +357,7 @@ ngx_poll_process_events(ngx_cycle_t *cyc
if (i == nevents - 1) {
nevents--;
} else {
- event_list[i].fd = -1;
+ event_list[i].fd = (ngx_socket_t) -1;
}
continue;
@@ -411,5 +421,15 @@ ngx_poll_init_conf(ngx_cycle_t *cycle, v
return NGX_CONF_OK;
}
+#if (NGX_LOAD_WSAPOLL)
+
+ if (!ngx_have_wsapoll) {
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
+ "poll is not available on this platform");
+ return NGX_CONF_ERROR;
+ }
+
+#endif
+
return NGX_CONF_OK;
}
diff --git a/src/os/win32/ngx_socket.h b/src/os/win32/ngx_socket.h
--- a/src/os/win32/ngx_socket.h
+++ b/src/os/win32/ngx_socket.h
@@ -200,6 +200,49 @@ extern LPFN_CONNECTEX ngx_co
extern LPFN_DISCONNECTEX ngx_disconnectex;
+#if (NGX_HAVE_POLL && !defined POLLIN)
+
+/*
+ * WSAPoll() is only available if _WIN32_WINNT >= 0x0600.
+ * If it is not available during compilation, we try to
+ * load it dynamically at runtime.
+ */
+
+#define NGX_LOAD_WSAPOLL 1
+
+#define POLLRDNORM 0x0100
+#define POLLRDBAND 0x0200
+#define POLLIN (POLLRDNORM | POLLRDBAND)
+#define POLLPRI 0x0400
+
+#define POLLWRNORM 0x0010
+#define POLLOUT (POLLWRNORM)
+#define POLLWRBAND 0x0020
+
+#define POLLERR 0x0001
+#define POLLHUP 0x0002
+#define POLLNVAL 0x0004
+
+typedef struct pollfd {
+
+ SOCKET fd;
+ SHORT events;
+ SHORT revents;
+
+} WSAPOLLFD, *PWSAPOLLFD, FAR *LPWSAPOLLFD;
+
+typedef int (WSAAPI *ngx_wsapoll_pt)(
+ LPWSAPOLLFD fdArray,
+ ULONG fds,
+ INT timeout
+ );
+
+extern ngx_wsapoll_pt WSAPoll;
+extern ngx_uint_t ngx_have_wsapoll;
+
+#endif
+
+
int ngx_tcp_push(ngx_socket_t s);
#define ngx_tcp_push_n "tcp_push()"
diff --git a/src/os/win32/ngx_win32_init.c b/src/os/win32/ngx_win32_init.c
--- a/src/os/win32/ngx_win32_init.c
+++ b/src/os/win32/ngx_win32_init.c
@@ -58,6 +58,12 @@ static GUID cx_guid = WSAID_CONNECTEX;
static GUID dx_guid = WSAID_DISCONNECTEX;
+#if (NGX_LOAD_WSAPOLL)
+ngx_wsapoll_pt WSAPoll;
+ngx_uint_t ngx_have_wsapoll;
+#endif
+
+
ngx_int_t
ngx_os_init(ngx_log_t *log)
{
@@ -223,6 +229,32 @@ ngx_os_init(ngx_log_t *log)
ngx_close_socket_n " failed");
}
+#if (NGX_LOAD_WSAPOLL)
+ {
+ HMODULE hmod;
+
+ hmod = GetModuleHandle("ws2_32.dll");
+ if (hmod == NULL) {
+ ngx_log_error(NGX_LOG_NOTICE, log, ngx_errno,
+ "GetModuleHandle(\"ws2_32.dll\") failed");
+ goto nopoll;
+ }
+
+ WSAPoll = (ngx_wsapoll_pt) GetProcAddress(hmod, "WSAPoll");
+ if (WSAPoll == NULL) {
+ ngx_log_error(NGX_LOG_NOTICE, log, ngx_errno,
+ "GetProcAddress(\"WSAPoll\") failed");
+ goto nopoll;
+ }
+
+ ngx_have_wsapoll = 1;
+
+ }
+
+nopoll:
+
+#endif
+
if (GetEnvironmentVariable("ngx_unique", ngx_unique, NGX_INT32_LEN + 1)
!= 0)
{
From mdounin at mdounin.ru Thu Jan 24 20:16:22 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Thu, 24 Jan 2019 20:16:22 +0000
Subject: [nginx] Win32: enabled both select and poll on Windows by default.
Message-ID:
details: https://hg.nginx.org/nginx/rev/c9235164bbf1
branches:
changeset: 7445:c9235164bbf1
user: Maxim Dounin
date: Thu Jan 24 22:00:13 2019 +0300
description:
Win32: enabled both select and poll on Windows by default.
Since we now have both select and poll on Windows, it is enough to
do not set EVENT_FOUND, auto/modules will enable both automatically.
diffstat:
auto/os/win32 | 8 +-------
1 files changed, 1 insertions(+), 7 deletions(-)
diffs (18 lines):
diff --git a/auto/os/win32 b/auto/os/win32
--- a/auto/os/win32
+++ b/auto/os/win32
@@ -32,13 +32,7 @@ case "$NGX_CC_NAME" in
esac
EVENT_MODULES="$EVENT_MODULES $IOCP_MODULE"
-EVENT_FOUND=YES
-
-if [ $EVENT_SELECT = NO ]; then
- have=NGX_HAVE_SELECT . auto/have
- CORE_SRCS="$CORE_SRCS $SELECT_SRCS"
- EVENT_MODULES="$EVENT_MODULES $SELECT_MODULE"
-fi
+#EVENT_FOUND=YES
have=NGX_HAVE_INET6 . auto/have
From mdounin at mdounin.ru Thu Jan 24 20:16:23 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Thu, 24 Jan 2019 20:16:23 +0000
Subject: [nginx] Win32: detection of connect() errors in select().
Message-ID:
details: https://hg.nginx.org/nginx/rev/9234e8d61aa0
branches:
changeset: 7446:9234e8d61aa0
user: Maxim Dounin
date: Thu Jan 24 22:00:44 2019 +0300
description:
Win32: detection of connect() errors in select().
On Windows, connect() errors are only reported via exceptfds descriptor set
from select(). Previously exceptfds was set to NULL, and connect() errors
were not detected at all, so connects to closed ports were waiting till
a timeout occurred.
Since ongoing connect() means that there will be a write event active,
except descriptor set is copied from the write one. While it is possible
to construct except descriptor set as a concatenation of both read and write
descriptor sets, this looks unneeded.
With this change, connect() errors are properly detected now when using
select(). Note well that it is not possible to detect connect() errors with
WSAPoll() (see https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/).
diffstat:
src/event/modules/ngx_win32_select_module.c | 17 +++++++++++++----
1 files changed, 13 insertions(+), 4 deletions(-)
diffs (56 lines):
diff --git a/src/event/modules/ngx_win32_select_module.c b/src/event/modules/ngx_win32_select_module.c
--- a/src/event/modules/ngx_win32_select_module.c
+++ b/src/event/modules/ngx_win32_select_module.c
@@ -26,6 +26,7 @@ static fd_set master_read_fd_set
static fd_set master_write_fd_set;
static fd_set work_read_fd_set;
static fd_set work_write_fd_set;
+static fd_set work_except_fd_set;
static ngx_uint_t max_read;
static ngx_uint_t max_write;
@@ -251,9 +252,11 @@ ngx_select_process_events(ngx_cycle_t *c
work_read_fd_set = master_read_fd_set;
work_write_fd_set = master_write_fd_set;
+ work_except_fd_set = master_write_fd_set;
if (max_read || max_write) {
- ready = select(0, &work_read_fd_set, &work_write_fd_set, NULL, tp);
+ ready = select(0, &work_read_fd_set, &work_write_fd_set,
+ &work_except_fd_set, tp);
} else {
@@ -306,14 +309,20 @@ ngx_select_process_events(ngx_cycle_t *c
if (ev->write) {
if (FD_ISSET(c->fd, &work_write_fd_set)) {
- found = 1;
+ found++;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"select write %d", c->fd);
}
+ if (FD_ISSET(c->fd, &work_except_fd_set)) {
+ found++;
+ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
+ "select except %d", c->fd);
+ }
+
} else {
if (FD_ISSET(c->fd, &work_read_fd_set)) {
- found = 1;
+ found++;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
"select read %d", c->fd);
}
@@ -327,7 +336,7 @@ ngx_select_process_events(ngx_cycle_t *c
ngx_post_event(ev, queue);
- nready++;
+ nready += found;
}
}
From mdounin at mdounin.ru Fri Jan 25 00:12:42 2019
From: mdounin at mdounin.ru (Maxim Dounin)
Date: Fri, 25 Jan 2019 03:12:42 +0300
Subject: PCRE2 support?
In-Reply-To: <5f5a8d73-77b5-bf62-d963-5e2927aa72e1@gmail.com>
References: <20180918121231.843FC2C50D50@mail.nginx.com>
<20180918155518.GQ56558@mdounin.ru>
<0522327a-8b2c-f066-ddd6-392207ec6c1d@thomas-ward.net>
<20190124182121.GP1877@mdounin.ru>
<5f5a8d73-77b5-bf62-d963-5e2927aa72e1@gmail.com>
Message-ID: <20190125001242.GR1877@mdounin.ru>
Hello!
On Thu, Jan 24, 2019 at 10:47:48AM -0800, PGNet Dev wrote:
> > Well, this depends on your point of view. If a project which
> > actually developed the library fails to introduce support to the
> > new version of the library - for an external observer this
> > suggests that there is something wrong with the new version.
>
> FUD 'suggestions' simply aren't needed.
Sure, they aren't. What is wrong with PCRE2 is clear from the
very start: it's a different library with different API. And
supporting PCRE2 is a question of advantages of PCRE2 over PCRE.
> The Exim project didn't develop the pcre2 library ... Philip Hazel did
> (https://www.pcre.org/current/doc/html/pcre2.html#SEC4), as a separate
> project.
Philip Hazel developed both Exim and the PCRE library, "originally
written for the Exim MTA". And PCRE2 claims to be a "major
version" of the PCRE library.
> Exim's last (? something newer out there?) rationale for not adopting it
> was simply,
>
> https://bugs.exim.org/show_bug.cgi?id=1878
>
> "The original PCRE support is not broken.
>
> If it is going to go away, then adding PCRE2 support becomes much more
> important, but I've seen nobody saying that yet."
I've posted this link in my first response in this thread 4 month
ago. The same rationale applies to any project already using
the PCRE library.
--
Maxim Dounin
http://mdounin.ru/
From sepherosa at gmail.com Mon Jan 28 09:06:35 2019
From: sepherosa at gmail.com (Sepherosa Ziehau)
Date: Mon, 28 Jan 2019 17:06:35 +0800
Subject: aio/unix: Use signal.sival which is standard
In-Reply-To: <20190124145914.GN1877@mdounin.ru>
References:
<47C75FB8-1DB2-4864-B5DA-13D915E73592@nginx.com>
<20190117132251.GI99070@mdounin.ru>
<76EB7D89-8048-4CB5-AB87-A94C2C52F808@nginx.com>
<20190122145429.GE1877@mdounin.ru>
<20190124145914.GN1877@mdounin.ru>
Message-ID:
Hi,
Thank you for the information!
Thanks,
sephe
On Thu, Jan 24, 2019 at 10:59 PM Maxim Dounin wrote:
>
> Hello!
>
> On Thu, Jan 24, 2019 at 10:07:57AM +0800, Sepherosa Ziehau wrote:
>
> > On Tue, Jan 22, 2019 at 10:54 PM Maxim Dounin wrote:
> > > This needs to be extended with some background information -
> > > notably why it used to be sigval_ptr, and why to switch to
> > > sival_ptr.
> >
> > I am not sure why it used to be sigval_ptr; seems to be a miss name in
> > FreeBSD. And the code seems to assume having KQUEUE == having sigval_ptr.
> >
> > As about why the switching:
> > - It's POSIX standard.
> > - It was noticed recently in DragonFly, since we removed this compat
> > field (sigval_ptr), since after scanning the source code in ports
> > system, nginx seems to be the only one using sigval_ptr.
>
> Yes, Sergey have details on hand. It was renamed (likely by
> accident) in 1999 (FreeBSD 4.0) when introducing SA_SIGINFO
> support[1]. Standard-complaint name was restored in 2005 (first
> released in FreeBSD 7.0 in 2008), retaining compatibility with
> previous versions[2][3]. Similar changes were committed in
> DragonFly in 2009[4].
>
> Since initial AIO support in nginx was introduced in 2003[5], it
> used the only name available at the moment.
>
> Switching to a standard name now is fine, especially giving that
> we can easily retain compatibility with previous versions.
>
> But at least some of these details need to be preserved in the
> commit log, and that's what I was asking Sergey about.
>
> [1] https://github.com/freebsd/freebsd/commit/53573bf465904188986e8c982e8019835628d6b2
> [2] https://github.com/freebsd/freebsd/commit/ae161ac2394e00bb3afca0667a13243d7963dfe2
> [3] https://github.com/freebsd/freebsd/commit/54f35995c2ce65f23beb667de4ccf3d68139a81a
> [4] https://gitweb.dragonflybsd.org/dragonfly.git/commit/36934016eeaca3abd418acb1c68bd391d3b54aa7
> [5] http://hg.nginx.org/nginx/rev/738fe44c70d5
>
> --
> Maxim Dounin
> http://mdounin.ru/
> _______________________________________________
> nginx-devel mailing list
> nginx-devel at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
--
Tomorrow Will Never Die
From maxim at nginx.com Mon Jan 28 10:23:45 2019
From: maxim at nginx.com (Maxim Konovalov)
Date: Mon, 28 Jan 2019 10:23:45 +0000
Subject: [nginx] Year 2019.
Message-ID:
details: https://hg.nginx.org/nginx/rev/f56a4c91b303
branches:
changeset: 7447:f56a4c91b303
user: Maxim Konovalov
date: Mon Jan 28 13:23:37 2019 +0300
description:
Year 2019.
diffstat:
docs/text/LICENSE | 4 ++--
1 ?????? ????????, 2 ???????(+), 2 ????????(-)
???????? (12 ?????):
diff -r 9234e8d61aa0 -r f56a4c91b303 docs/text/LICENSE
--- a/docs/text/LICENSE Thu Jan 24 22:00:44 2019 +0300
+++ b/docs/text/LICENSE Mon Jan 28 13:23:37 2019 +0300
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2002-2018 Igor Sysoev
- * Copyright (C) 2011-2018 Nginx, Inc.
+ * Copyright (C) 2002-2019 Igor Sysoev
+ * Copyright (C) 2011-2019 Nginx, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
From xeioex at nginx.com Mon Jan 28 13:20:41 2019
From: xeioex at nginx.com (Dmitry Volyntsev)
Date: Mon, 28 Jan 2019 13:20:41 +0000
Subject: [njs] HTTP: removed response object deprecated in 0.2.2.
Message-ID:
details: https://hg.nginx.org/njs/rev/23df46c40a53
branches:
changeset: 737:23df46c40a53
user: Dmitry Volyntsev
date: Mon Jan 28 16:17:42 2019 +0300
description:
HTTP: removed response object deprecated in 0.2.2.
diffstat:
nginx/ngx_http_js_module.c | 303 +--------------------------------------------
1 files changed, 5 insertions(+), 298 deletions(-)
diffs (467 lines):
diff -r 72fce46a7669 -r 23df46c40a53 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c Wed Jan 23 19:48:19 2019 +0300
+++ b/nginx/ngx_http_js_module.c Mon Jan 28 16:17:42 2019 +0300
@@ -15,7 +15,6 @@
typedef struct {
njs_vm_t *vm;
const njs_extern_t *req_proto;
- const njs_extern_t *res_proto;
} ngx_http_js_main_conf_t;
@@ -27,9 +26,9 @@ typedef struct {
typedef struct {
njs_vm_t *vm;
ngx_log_t *log;
- njs_opaque_value_t args[2];
ngx_uint_t done;
ngx_int_t status;
+ njs_opaque_value_t request;
njs_opaque_value_t request_body;
ngx_str_t redirect_uri;
} ngx_http_js_ctx_t;
@@ -62,8 +61,6 @@ static void ngx_http_js_cleanup_vm(void
static njs_ret_t ngx_http_js_ext_get_string(njs_vm_t *vm, njs_value_t *value,
void *obj, uintptr_t data);
-static njs_ret_t ngx_http_js_ext_set_string(njs_vm_t *vm, void *obj,
- uintptr_t data, nxt_str_t *value);
static njs_ret_t ngx_http_js_ext_foreach_header(njs_vm_t *vm, void *obj,
void *next, uintptr_t data);
static njs_ret_t ngx_http_js_ext_next_header(njs_vm_t *vm, njs_value_t *value,
@@ -80,10 +77,6 @@ static njs_ret_t ngx_http_js_ext_get_sta
void *obj, uintptr_t data);
static njs_ret_t ngx_http_js_ext_set_status(njs_vm_t *vm, void *obj,
uintptr_t data, nxt_str_t *value);
-static njs_ret_t ngx_http_js_ext_get_content_length(njs_vm_t *vm,
- njs_value_t *value, void *obj, uintptr_t data);
-static njs_ret_t ngx_http_js_ext_set_content_length(njs_vm_t *vm, void *obj,
- uintptr_t data, nxt_str_t *value);
static njs_ret_t ngx_http_js_ext_send_header(njs_vm_t *vm, njs_value_t *args,
nxt_uint_t nargs, njs_index_t unused);
static njs_ret_t ngx_http_js_ext_send(njs_vm_t *vm, njs_value_t *args,
@@ -110,10 +103,6 @@ static njs_ret_t ngx_http_js_ext_get_rem
njs_value_t *value, void *obj, uintptr_t data);
static njs_ret_t ngx_http_js_ext_get_request_body(njs_vm_t *vm,
njs_value_t *value, void *obj, uintptr_t data);
-static njs_ret_t ngx_http_js_ext_get_headers(njs_vm_t *vm, njs_value_t *value,
- void *obj, uintptr_t data);
-static njs_ret_t ngx_http_js_ext_foreach_headers(njs_vm_t *vm, void *obj,
- void *next); /*FIXME*/
static njs_ret_t ngx_http_js_ext_get_header_in(njs_vm_t *vm, njs_value_t *value,
void *obj, uintptr_t data);
static njs_ret_t ngx_http_js_ext_foreach_header_in(njs_vm_t *vm, void *obj,
@@ -126,8 +115,6 @@ static njs_ret_t ngx_http_js_ext_next_ar
void *obj, void *next);
static njs_ret_t ngx_http_js_ext_get_variable(njs_vm_t *vm, njs_value_t *value,
void *obj, uintptr_t data);
-static njs_ret_t ngx_http_js_ext_get_response(njs_vm_t *vm, njs_value_t *value,
- void *obj, uintptr_t data);
static njs_ret_t ngx_http_js_ext_subrequest(njs_vm_t *vm, njs_value_t *args,
nxt_uint_t nargs, njs_index_t unused);
static ngx_int_t ngx_http_js_subrequest(ngx_http_request_t *r,
@@ -217,106 +204,6 @@ ngx_module_t ngx_http_js_module = {
};
-static njs_external_t ngx_http_js_ext_response[] = {
-
- { nxt_string("headers"),
- NJS_EXTERN_OBJECT,
- NULL,
- 0,
- ngx_http_js_ext_get_header_out,
- ngx_http_js_ext_set_header_out,
- NULL,
- ngx_http_js_ext_foreach_header_out,
- ngx_http_js_ext_next_header,
- NULL,
- 0 },
-
- { nxt_string("status"),
- NJS_EXTERN_PROPERTY,
- NULL,
- 0,
- ngx_http_js_ext_get_status,
- ngx_http_js_ext_set_status,
- NULL,
- NULL,
- NULL,
- NULL,
- offsetof(ngx_http_request_t, headers_out.status) },
-
- { nxt_string("contentType"),
- NJS_EXTERN_PROPERTY,
- NULL,
- 0,
- ngx_http_js_ext_get_string,
- ngx_http_js_ext_set_string,
- NULL,
- NULL,
- NULL,
- NULL,
- offsetof(ngx_http_request_t, headers_out.content_type) },
-
- { nxt_string("contentLength"),
- NJS_EXTERN_PROPERTY,
- NULL,
- 0,
- ngx_http_js_ext_get_content_length,
- ngx_http_js_ext_set_content_length,
- NULL,
- NULL,
- NULL,
- NULL,
- 0 },
-
- { nxt_string("sendHeader"),
- NJS_EXTERN_METHOD,
- NULL,
- 0,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- ngx_http_js_ext_send_header,
- 0 },
-
- { nxt_string("send"),
- NJS_EXTERN_METHOD,
- NULL,
- 0,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- ngx_http_js_ext_send,
- 0 },
-
- { nxt_string("finish"),
- NJS_EXTERN_METHOD,
- NULL,
- 0,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- ngx_http_js_ext_finish,
- 0 },
-
- { nxt_string("return"),
- NJS_EXTERN_METHOD,
- NULL,
- 0,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- ngx_http_js_ext_return,
- 0 },
-};
-
-
static njs_external_t ngx_http_js_ext_request[] = {
{ nxt_string("uri"),
@@ -379,18 +266,6 @@ static njs_external_t ngx_http_js_ext_r
NULL,
0 },
- { nxt_string("body"),
- NJS_EXTERN_PROPERTY,
- NULL,
- 0,
- ngx_http_js_ext_get_reply_body,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0 },
-
{ nxt_string("requestBody"),
NJS_EXTERN_PROPERTY,
NULL,
@@ -415,18 +290,6 @@ static njs_external_t ngx_http_js_ext_r
NULL,
0 },
- { nxt_string("headers"),
- NJS_EXTERN_OBJECT,
- NULL,
- 0,
- ngx_http_js_ext_get_headers,
- NULL,
- NULL,
- ngx_http_js_ext_foreach_headers,
- ngx_http_js_ext_next_header,
- NULL,
- 0 },
-
{ nxt_string("headersIn"),
NJS_EXTERN_OBJECT,
NULL,
@@ -487,18 +350,6 @@ static njs_external_t ngx_http_js_ext_r
NULL,
0 },
- { nxt_string("response"),
- NJS_EXTERN_PROPERTY,
- NULL,
- 0,
- ngx_http_js_ext_get_response,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0 },
-
{ nxt_string("subrequest"),
NJS_EXTERN_METHOD,
NULL,
@@ -622,18 +473,6 @@ static njs_external_t ngx_http_js_exter
NULL,
NULL,
0 },
-
- { nxt_string("response"),
- NJS_EXTERN_OBJECT,
- ngx_http_js_ext_response,
- nxt_nitems(ngx_http_js_ext_response),
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- 0 },
};
@@ -707,7 +546,7 @@ ngx_http_js_content_event_handler(ngx_ht
ctx->status = NGX_HTTP_INTERNAL_SERVER_ERROR;
- if (njs_vm_call(ctx->vm, func, njs_value_arg(ctx->args), 2) != NJS_OK) {
+ if (njs_vm_call(ctx->vm, func, njs_value_arg(&ctx->request), 1) != NJS_OK) {
njs_vm_retval_to_ext_string(ctx->vm, &exception);
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
@@ -839,7 +678,7 @@ ngx_http_js_variable(ngx_http_request_t
pending = njs_vm_pending(ctx->vm);
- if (njs_vm_call(ctx->vm, func, njs_value_arg(ctx->args), 2) != NJS_OK) {
+ if (njs_vm_call(ctx->vm, func, njs_value_arg(&ctx->request), 1) != NJS_OK) {
njs_vm_retval_to_ext_string(ctx->vm, &exception);
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
@@ -922,18 +761,12 @@ ngx_http_js_init_vm(ngx_http_request_t *
return NGX_ERROR;
}
- rc = njs_vm_external_create(ctx->vm, njs_value_arg(&ctx->args[0]),
+ rc = njs_vm_external_create(ctx->vm, njs_value_arg(&ctx->request),
jmcf->req_proto, r);
if (rc != NXT_OK) {
return NGX_ERROR;
}
- rc = njs_vm_external_create(ctx->vm, njs_value_arg(&ctx->args[1]),
- jmcf->res_proto, r);
- if (rc != NXT_OK) {
- return NGX_ERROR;
- }
-
return NGX_OK;
}
@@ -975,31 +808,6 @@ ngx_http_js_ext_get_string(njs_vm_t *vm,
static njs_ret_t
-ngx_http_js_ext_set_string(njs_vm_t *vm, void *obj, uintptr_t data,
- nxt_str_t *value)
-{
- char *p = obj;
-
- ngx_str_t *field;
- ngx_http_request_t *r;
-
- r = (ngx_http_request_t *) obj;
-
- field = (ngx_str_t *) (p + data);
- field->len = value->length;
-
- field->data = ngx_pnalloc(r->pool, value->length);
- if (field->data == NULL) {
- return NJS_ERROR;
- }
-
- ngx_memcpy(field->data, value->start, value->length);
-
- return NJS_OK;
-}
-
-
-static njs_ret_t
ngx_http_js_ext_foreach_header(njs_vm_t *vm, void *obj, void *next,
uintptr_t data)
{
@@ -1217,40 +1025,6 @@ ngx_http_js_ext_set_status(njs_vm_t *vm,
static njs_ret_t
-ngx_http_js_ext_get_content_length(njs_vm_t *vm, njs_value_t *value, void *obj,
- uintptr_t data)
-{
- ngx_http_request_t *r;
-
- r = (ngx_http_request_t *) obj;
-
- njs_value_number_set(value, r->headers_out.content_length_n);
-
- return NJS_OK;
-}
-
-
-static njs_ret_t
-ngx_http_js_ext_set_content_length(njs_vm_t *vm, void *obj, uintptr_t data,
- nxt_str_t *value)
-{
- ngx_int_t n;
- ngx_http_request_t *r;
-
- n = ngx_atoi(value->start, value->length);
- if (n == NGX_ERROR) {
- return NJS_ERROR;
- }
-
- r = (ngx_http_request_t *) obj;
-
- r->headers_out.content_length_n = n;
-
- return NJS_OK;
-}
-
-
-static njs_ret_t
ngx_http_js_ext_send_header(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
{
@@ -1656,27 +1430,6 @@ done:
static njs_ret_t
-ngx_http_js_ext_get_headers(njs_vm_t *vm, njs_value_t *value,
- void *obj, uintptr_t data)
-{
- ngx_http_js_ctx_t *ctx;
- ngx_http_request_t *r;
-
- r = (ngx_http_request_t *) obj;
-
- ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
-
- if (ctx->done) {
- /* simulate Reply.headers behavior */
-
- return ngx_http_js_ext_get_header_out(vm, value, obj, data);
- }
-
- return ngx_http_js_ext_get_header_in(vm, value, obj, data);
-}
-
-
-static njs_ret_t
ngx_http_js_ext_get_header_in(njs_vm_t *vm, njs_value_t *value, void *obj,
uintptr_t data)
{
@@ -1698,26 +1451,6 @@ ngx_http_js_ext_get_header_in(njs_vm_t *
static njs_ret_t
-ngx_http_js_ext_foreach_headers(njs_vm_t *vm, void *obj, void *next)
-{
- ngx_http_js_ctx_t *ctx;
- ngx_http_request_t *r;
-
- r = (ngx_http_request_t *) obj;
-
- ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
-
- if (ctx->done) {
- /* simulate Reply.headers behavior */
-
- return ngx_http_js_ext_foreach_header_out(vm, obj, next);
- }
-
- return ngx_http_js_ext_foreach_header_in(vm, obj, next);
-}
-
-
-static njs_ret_t
ngx_http_js_ext_foreach_header_in(njs_vm_t *vm, void *obj, void *next)
{
return ngx_http_js_ext_foreach_header(vm, obj, next,
@@ -1834,23 +1567,6 @@ ngx_http_js_ext_get_variable(njs_vm_t *v
static njs_ret_t
-ngx_http_js_ext_get_response(njs_vm_t *vm, njs_value_t *value, void *obj,
- uintptr_t data)
-{
- ngx_http_js_ctx_t *ctx;
- ngx_http_request_t *r;
-
- r = (ngx_http_request_t *) obj;
-
- ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
-
- njs_value_assign(value, njs_value_arg(&ctx->args[1]));
-
- return NJS_OK;
-}
-
-
-static njs_ret_t
ngx_http_js_ext_subrequest(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
njs_index_t unused)
{
@@ -2189,7 +1905,7 @@ ngx_http_js_ext_get_parent(njs_vm_t *vm,
return NJS_ERROR;
}
- njs_value_assign(value, njs_value_arg(&ctx->args[0]));
+ njs_value_assign(value, njs_value_arg(&ctx->request));
return NJS_OK;
}
@@ -2417,14 +2133,6 @@ ngx_http_js_include(ngx_conf_t *cf, ngx_
return NGX_CONF_ERROR;
}
- jmcf->res_proto = njs_vm_external_prototype(jmcf->vm,
- &ngx_http_js_externals[1]);
- if (jmcf->res_proto == NULL) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "failed to add response proto");
- return NGX_CONF_ERROR;
- }
-
rc = njs_vm_compile(jmcf->vm, &start, end);
if (rc != NJS_OK) {
@@ -2520,7 +2228,6 @@ ngx_http_js_create_main_conf(ngx_conf_t
*
* conf->vm = NULL;
* conf->req_proto = NULL;
- * conf->res_proto = NULL;
*/
return conf;
From pluknet at nginx.com Mon Jan 28 17:16:32 2019
From: pluknet at nginx.com (Sergey Kandaurov)
Date: Mon, 28 Jan 2019 17:16:32 +0000
Subject: [nginx] Fixed portability issues with union sigval.
Message-ID:
details: https://hg.nginx.org/nginx/rev/7f035fd1ec7b
branches:
changeset: 7448:7f035fd1ec7b
user: Sergey Kandaurov
date: Mon Jan 28 14:33:31 2019 +0000
description:
Fixed portability issues with union sigval.
AIO support in nginx was originally developed against FreeBSD versions 4-6,
where the sival_ptr field was named as sigval_ptr (seemingly by mistake[1]),
which made nginx use the only name available then. The standard-complaint
name was restored in 2005 (first appeared in FreeBSD 7.0, 2008), retaining
compatibility with previous versions[2][3]. In DragonFly, similar changes
were committed in 2009[4], with backward compatibility recently removed[5].
The change switches to the standard name, retaining compatibility with old
FreeBSD versions.
[1] https://svnweb.freebsd.org/changeset/base/48621
[2] https://svnweb.freebsd.org/changeset/base/152029
[3] https://svnweb.freebsd.org/changeset/base/174003
[4] https://gitweb.dragonflybsd.org/dragonfly.git/commit/3693401
[5] https://gitweb.dragonflybsd.org/dragonfly.git/commit/7875042
diffstat:
src/os/unix/ngx_file_aio_read.c | 2 +-
src/os/unix/ngx_freebsd_config.h | 6 ++++++
2 files changed, 7 insertions(+), 1 deletions(-)
diffs (30 lines):
diff -r f56a4c91b303 -r 7f035fd1ec7b src/os/unix/ngx_file_aio_read.c
--- a/src/os/unix/ngx_file_aio_read.c Mon Jan 28 13:23:37 2019 +0300
+++ b/src/os/unix/ngx_file_aio_read.c Mon Jan 28 14:33:31 2019 +0000
@@ -110,7 +110,7 @@ ngx_file_aio_read(ngx_file_t *file, u_ch
#if (NGX_HAVE_KQUEUE)
aio->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue;
aio->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT;
- aio->aiocb.aio_sigevent.sigev_value.sigval_ptr = ev;
+ aio->aiocb.aio_sigevent.sigev_value.sival_ptr = ev;
#endif
ev->handler = ngx_file_aio_event_handler;
diff -r f56a4c91b303 -r 7f035fd1ec7b src/os/unix/ngx_freebsd_config.h
--- a/src/os/unix/ngx_freebsd_config.h Mon Jan 28 13:23:37 2019 +0300
+++ b/src/os/unix/ngx_freebsd_config.h Mon Jan 28 14:33:31 2019 +0000
@@ -89,8 +89,14 @@
#if (NGX_HAVE_FILE_AIO)
+
#include
typedef struct aiocb ngx_aiocb_t;
+
+#if (__FreeBSD_version < 700005 && !defined __DragonFly__)
+#define sival_ptr sigval_ptr
+#endif
+
#endif
From pluknet at nginx.com Mon Jan 28 17:16:34 2019
From: pluknet at nginx.com (Sergey Kandaurov)
Date: Mon, 28 Jan 2019 17:16:34 +0000
Subject: [nginx] Removed --test-build-eventport workaround for old FreeBSD
versions.
Message-ID: