Will nginx support quic-lb feature later?

2020-07-24 Thread 曾柯(毅丝)

Dear NGINX maintainer:
 Will nginx support quic-lb feature which was described in 
https://tools.ietf.org/html/draft-ietf-quic-load-balancers-03 latter?  We 
firmly believe that nginx is the most appropriate LB product to do this(Other 
LB product such as LVS, have to modify kernel). If you agree with this, we are 
very happy to contribute our code to nginx community(We will contribute our 
code to nginx-quic branch).___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

[njs] Fixed pre/post increment/decrement in assignment operations.

2020-07-24 Thread Alexander Borisov
details:   https://hg.nginx.org/njs/rev/78f0887e5aa6
branches:  
changeset: 1478:78f0887e5aa6
user:  Alexander Borisov 
date:  Thu Jul 23 13:24:10 2020 +0300
description:
Fixed pre/post increment/decrement in assignment operations.

Previously, the compound assignment operations did not create temporary
index for increments/decrements in the generator. The result was that
the increment/decrement changed the value immediately in place, which
led to incorrect calculations.

The fix is to use a separate temporary index for increments/decrements in
assignment operations.

This closes #271 issue on GitHub.

diffstat:

 src/njs_generator.c  |  30 -
 src/njs_lexer.h  |  11 +
 src/test/njs_unit_test.c |  56 
 3 files changed, 91 insertions(+), 6 deletions(-)

diffs (165 lines):

diff -r 7f5c5a425d03 -r 78f0887e5aa6 src/njs_generator.c
--- a/src/njs_generator.c   Wed Jul 22 15:21:15 2020 +0300
+++ b/src/njs_generator.c   Thu Jul 23 13:24:10 2020 +0300
@@ -1799,7 +1799,7 @@ njs_generate_operation_assignment(njs_vm
 njs_parser_node_t *node)
 {
 njs_int_t  ret;
-njs_index_tindex;
+njs_index_tindex, src;
 njs_parser_node_t  *lvalue, *expr, *object, *property;
 njs_vmcode_move_t  *move;
 njs_vmcode_3addr_t *code;
@@ -1876,6 +1876,34 @@ njs_generate_operation_assignment(njs_vm
 return ret;
 }
 
+if (njs_slow_path(njs_parser_has_side_effect(node->right))) {
+/*
+ * Preserve object and property values stored in variables in a case
+ * if the variables can be changed by side effects in expression.
+ */
+if (object->token_type == NJS_TOKEN_NAME) {
+src = object->index;
+
+index = njs_generate_node_temp_index_get(vm, generator, object);
+if (njs_slow_path(index == NJS_INDEX_ERROR)) {
+return NJS_ERROR;
+}
+
+njs_generate_code_move(generator, move, index, src, object);
+}
+
+if (property->token_type == NJS_TOKEN_NAME) {
+src = property->index;
+
+index = njs_generate_node_temp_index_get(vm, generator, property);
+if (njs_slow_path(index == NJS_INDEX_ERROR)) {
+return NJS_ERROR;
+}
+
+njs_generate_code_move(generator, move, index, src, property);
+}
+}
+
 index = njs_generate_node_temp_index_get(vm, generator, node);
 if (njs_slow_path(index == NJS_INDEX_ERROR)) {
 return NJS_ERROR;
diff -r 7f5c5a425d03 -r 78f0887e5aa6 src/njs_lexer.h
--- a/src/njs_lexer.h   Wed Jul 22 15:21:15 2020 +0300
+++ b/src/njs_lexer.h   Thu Jul 23 13:24:10 2020 +0300
@@ -51,7 +51,12 @@ typedef enum {
 NJS_TOKEN_BITWISE_XOR_ASSIGNMENT,
 NJS_TOKEN_BITWISE_AND_ASSIGNMENT,
 
-#define NJS_TOKEN_LAST_ASSIGNMENT   NJS_TOKEN_BITWISE_AND_ASSIGNMENT
+NJS_TOKEN_INCREMENT,
+NJS_TOKEN_DECREMENT,
+NJS_TOKEN_POST_INCREMENT,
+NJS_TOKEN_POST_DECREMENT,
+
+#define NJS_TOKEN_LAST_ASSIGNMENT   NJS_TOKEN_POST_DECREMENT
 
 NJS_TOKEN_EQUAL,
 NJS_TOKEN_STRICT_EQUAL,
@@ -60,13 +65,9 @@ typedef enum {
 
 NJS_TOKEN_ADDITION,
 NJS_TOKEN_UNARY_PLUS,
-NJS_TOKEN_INCREMENT,
-NJS_TOKEN_POST_INCREMENT,
 
 NJS_TOKEN_SUBSTRACTION,
 NJS_TOKEN_UNARY_NEGATION,
-NJS_TOKEN_DECREMENT,
-NJS_TOKEN_POST_DECREMENT,
 
 NJS_TOKEN_MULTIPLICATION,
 
diff -r 7f5c5a425d03 -r 78f0887e5aa6 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c  Wed Jul 22 15:21:15 2020 +0300
+++ b/src/test/njs_unit_test.c  Thu Jul 23 13:24:10 2020 +0300
@@ -2183,6 +2183,20 @@ static njs_unit_test_t  njs_test[] =
  "var b = ++a; a +' '+ b"),
   njs_str("NaN NaN") },
 
+{ njs_str("var a = 0; a = a + ++a; a"),
+  njs_str("1") },
+
+{ njs_str("var a = 0; a += a + ++a; a"),
+  njs_str("1") },
+
+{ njs_str("var i = 0, arr = ['a', 'b'];"
+  "arr[i] = arr[i] + arr[++i]; arr"),
+  njs_str("ab,b") },
+
+{ njs_str("var i = 0, arr = ['a', 'b'];"
+  "arr[i] += arr[i] + arr[++i]; arr"),
+  njs_str("aab,b") },
+
 /* Post increment. */
 
 { njs_str("var a = 1;   a++"),
@@ -2265,6 +2279,20 @@ static njs_unit_test_t  njs_test[] =
  "var b = a++; a +' '+ b"),
   njs_str("NaN NaN") },
 
+{ njs_str("var a = 0; a = a + a++; a"),
+  njs_str("0") },
+
+{ njs_str("var a = 0; a += a + a++; a"),
+  njs_str("0") },
+
+{ njs_str("var i = 1, arr = ['a', 'b'];"
+  "arr[i] = arr[i] + arr[i++]; arr"),
+  njs_str("a,bb") },
+
+{ njs_str("var i = 1, arr = ['a', 'b'];"
+  "arr[i] += arr[i] + arr[i++]; arr"),
+  njs_str("a,bbb") },
+
 /* Decrement. */
 
 { njs_str("var a = 1;   --a"),
@@ -2347,6 +2375,20 @@ static njs_unit_test_t  njs_test[] =
  "var b = --a; a +' '+ b"),
   njs

Re: [PATCH] During background update, nginx can't add "Range" header

2020-07-24 Thread Roman Arutyunyan
Hi,

> On 23 Jul 2020, at 08:29, Sangdeuk Kwon  wrote:
> 
> # HG changeset patch  
>   
> # User Sangdeuk Kwon  >
> # Date 1595481798 -32400  
>   
> #  Thu Jul 23 14:23:18 2020 +0900 
>   
> # Node ID 90e5ccf7c229322079ba1b61b4241ed69dfc09b2
>   
> # Parent  4f30f75dbdf33d6fae9e70086e0df5cbab7db027
>   
> During background update, nginx can't add "Range" header  
>   
>   
>   
> If the configuration is "slice enabled" and "proxy_cache_use_stale updating"  
>   
> and "proxy_cache_background_update on",   
>   
> nginx can't get "$slice_range" value during background update.
>   
> nginx sends request to upstream without "Range" header.   
>   
> The re-fetched content is saved by cache key of absent "$slice_range".
>   
> So, nginx always serves stale content even though after re-fetching new 
> content.

This is correct.  The slice module does not work with background updates.

>   
>   
> slice 1k; 
>   
> proxy_cache_use_stale updating;   
>   
> proxy_cache_background_update on; 
>   
> proxy_cache_key "$host$uri[$slice_range]  
>   
>   
>   
> diff -r 4f30f75dbdf3 -r 90e5ccf7c229 
> src/http/modules/ngx_http_slice_filter_module.c
> --- a/src/http/modules/ngx_http_slice_filter_module.c   Tue Jul 21 20:34:29 
> 2020 +0300
> +++ b/src/http/modules/ngx_http_slice_filter_module.c   Thu Jul 23 14:23:18 
> 2020 +0900
> @@ -400,9 +400,12 @@  
>   
>  ngx_http_slice_loc_conf_t  *slcf;
>   
>   
>   
>  ctx = ngx_http_get_module_ctx(r, ngx_http_slice_filter_module);  
>   
> +if (r->background && r != r->main && r->main != r->parent) { 
>   
> +ctx = ngx_http_get_module_ctx(r->parent, 
> ngx_http_slice_filter_module);
> +}

Here you’re trying to get the parent request’s context to access the slice 
range.
But slice range is being constantly updated.  So there’s no guarantee that you 
get
the right slice range.

The right solution would be to pass the slice range to the background update
subrequest as an argument or a part of uri.  But that does not seem to be 
possible
within the current background update implementation. Probably there’s a way to 
save
and then access the right slice using njs.

>  
>   
>   
>  if (ctx == NULL) {   
>   
> -if (r != r->main || r->headers_out.status) { 
>   
> +if ((r != r->main && !r->background) || r->headers_out.status) { 
>   
>  v->not_found = 1;
>   
>  return NGX_OK;   
>   
>  }

Here you are creating a new ctx for the background update subrequest,
which suggests that you want to update the entire response rather that
only one slice.

> ___
> nginx-devel mailing list
> nginx-devel@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel

___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel

[njs] Improved fs.mkdir() to support recursive directory creation.

2020-07-24 Thread Dmitry Volyntsev
details:   https://hg.nginx.org/njs/rev/cb2ff67e595d
branches:  
changeset: 1480:cb2ff67e595d
user:  Artem S. Povalyukhin 
date:  Wed Jul 15 15:51:06 2020 +0300
description:
Improved fs.mkdir() to support recursive directory creation.

diffstat:

 src/njs_fs.c   |  112 
 test/js/fs_promises_008.js |   79 +++
 test/njs_expect_test.exp   |3 +
 3 files changed, 183 insertions(+), 11 deletions(-)

diffs (230 lines):

diff -r 354318f9b00f -r cb2ff67e595d src/njs_fs.c
--- a/src/njs_fs.c  Fri Jul 24 14:02:04 2020 +
+++ b/src/njs_fs.c  Wed Jul 15 15:51:06 2020 +0300
@@ -70,6 +70,9 @@ static njs_int_t njs_fs_error(njs_vm_t *
 static njs_int_t njs_fs_result(njs_vm_t *vm, njs_value_t *result,
 njs_index_t calltype, const njs_value_t* callback, njs_uint_t nargs);
 
+static njs_int_t njs_fs_make_path(njs_vm_t *vm, const char *path, mode_t md,
+njs_bool_t recursive, njs_value_t *retval);
+
 static int njs_fs_flags(njs_vm_t *vm, njs_value_t *value, int default_flags);
 static mode_t njs_fs_mode(njs_vm_t *vm, njs_value_t *value,
 mode_t default_mode);
@@ -828,18 +831,8 @@ njs_fs_mkdir(njs_vm_t *vm, njs_value_t *
 return NJS_ERROR;
 }
 
-if (njs_is_true(&recursive)) {
-njs_type_error(vm, "\"options.recursive\" is not supported");
-return NJS_ERROR;
-}
-
-njs_set_undefined(&retval);
-
-ret = mkdir(file_path, md);
-if (njs_slow_path(ret != 0)) {
-ret = njs_fs_error(vm, "mkdir", strerror(errno), path, errno,
+ret = njs_fs_make_path(vm, file_path, md, njs_is_true(&recursive),
&retval);
-}
 
 if (ret == NJS_OK) {
 return njs_fs_result(vm, &retval, calltype, callback, 1);
@@ -1138,6 +1131,103 @@ njs_fs_fd_read(njs_vm_t *vm, int fd, njs
 }
 
 
+static njs_int_t
+njs_fs_make_path(njs_vm_t *vm, const char *path, mode_t md,
+njs_bool_t recursive, njs_value_t *retval)
+{
+size_t   size;
+ssize_t  length;
+njs_int_tret;
+const char   *p, *prev;
+njs_value_t  value;
+struct stat  sb;
+char path_buf[MAXPATHLEN];
+
+njs_set_undefined(retval);
+
+if (!recursive) {
+ret = mkdir(path, md);
+if (ret != 0) {
+goto failed;
+}
+
+return NJS_OK;
+}
+
+ret = stat(path, &sb);
+if (ret == 0) {
+if (!S_ISDIR(sb.st_mode)) {
+errno = ENOTDIR;
+goto failed;
+}
+
+return NJS_OK;
+}
+
+if (errno != ENOENT) {
+goto failed;
+}
+
+p = path;
+prev = p;
+
+for ( ;; ) {
+p = strchr(prev + 1, '/');
+if (p == NULL) {
+break;
+}
+
+if (njs_slow_path((p - path) > MAXPATHLEN)) {
+njs_internal_error(vm, "too large path");
+return NJS_OK;
+}
+
+memcpy(&path_buf[prev - path], &path[prev - path], p - prev);
+path_buf[p - path] = '\0';
+
+ret = stat(path_buf, &sb);
+if (ret == 0) {
+if (!S_ISDIR(sb.st_mode)) {
+errno = ENOTDIR;
+goto failed;
+}
+
+} else {
+ret = mkdir(path_buf, md);
+if (ret != 0) {
+goto failed;
+}
+}
+
+path_buf[p - path] = '/';
+prev = p;
+}
+
+ret = mkdir(path, md);
+if (ret != 0 && errno != EEXIST) {
+goto failed;
+}
+
+return NJS_OK;
+
+failed:
+
+size = njs_strlen(path);
+length = njs_utf8_length((u_char *) path, size);
+if (njs_slow_path(length < 0)) {
+length = 0;
+}
+
+ret = njs_string_new(vm, &value, (u_char *) path, size, length);
+if (ret != NJS_OK) {
+return NJS_ERROR;
+}
+
+return njs_fs_error(vm, "mkdir", strerror(errno), &value, errno,
+retval);
+}
+
+
 static int
 njs_fs_flags(njs_vm_t *vm, njs_value_t *value, int default_flags)
 {
diff -r 354318f9b00f -r cb2ff67e595d test/js/fs_promises_008.js
--- /dev/null   Thu Jan 01 00:00:00 1970 +
+++ b/test/js/fs_promises_008.jsWed Jul 15 15:51:06 2020 +0300
@@ -0,0 +1,79 @@
+var fs = require('fs');
+var fsp  = fs.promises;
+var dname = './build/test/fs_promises_αβγ_008/';
+var path = 'one/two/three/αβγ';
+
+var wipePath = (root, path, nofail) => {
+path
+.split('/')
+.map((x, i, a) => {
+return root + a.slice(0, i + 1).join('/');
+})
+.reverse()
+.map((dir) => {
+try {
+fs.rmdirSync(dir);
+} catch (e) {
+if (!nofail) {
+throw e;
+}
+}
+});
+};
+
+var testSync = () => new Promise((resolve, reject) => {
+try {
+wipePath(dname, path + '/' + path, true);
+fs.rmdirSync(dname);
+} catch (e) {
+}
+
+try {
+fs.mkdirSync(dname);
+
+ 

[njs] Improved String.prototype.toString() for ordinary strings.

2020-07-24 Thread Dmitry Volyntsev
details:   https://hg.nginx.org/njs/rev/354318f9b00f
branches:  
changeset: 1479:354318f9b00f
user:  Dmitry Volyntsev 
date:  Fri Jul 24 14:02:04 2020 +
description:
Improved String.prototype.toString() for ordinary strings.

Allowing converting all strings to encodings 'hex', 'base64', 'base64url'.

diffstat:

 src/njs_string.c |  9 ++---
 src/test/njs_unit_test.c |  3 ---
 2 files changed, 2 insertions(+), 10 deletions(-)

diffs (40 lines):

diff -r 78f0887e5aa6 -r 354318f9b00f src/njs_string.c
--- a/src/njs_string.c  Thu Jul 23 13:24:10 2020 +0300
+++ b/src/njs_string.c  Fri Jul 24 14:02:04 2020 +
@@ -738,9 +738,9 @@ njs_string_prototype_value_of(njs_vm_t *
 
 
 /*
- * String.toString([encoding]).
+ * String.prototype.toString([encoding]).
  * Returns the string as is if no additional argument is provided,
- * otherwise converts a byte string into an encoded string: hex, base64,
+ * otherwise converts a string into an encoded string: hex, base64,
  * base64url.
  */
 
@@ -771,11 +771,6 @@ njs_string_prototype_to_string(njs_vm_t 
 
 (void) njs_string_prop(&string, &value);
 
-if (njs_slow_path(string.length != 0)) {
-njs_type_error(vm, "argument must be a byte string");
-return NJS_ERROR;
-}
-
 njs_string_get(&args[1], &enc);
 
 str.length = string.size;
diff -r 78f0887e5aa6 -r 354318f9b00f src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c  Thu Jul 23 13:24:10 2020 +0300
+++ b/src/test/njs_unit_test.c  Fri Jul 24 14:02:04 2020 +
@@ -895,9 +895,6 @@ static njs_unit_test_t  njs_test[] =
 { njs_str("'A'.toString()"),
   njs_str("A") },
 
-{ njs_str("'A'.toString('hex')"),
-  njs_str("TypeError: argument must be a byte string") },
-
 { njs_str("'A'.toBytes().toString('latin1')"),
   njs_str("TypeError: Unknown encoding: \"latin1\"") },
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: [PATCH] Core: enclosed parameters of macros in parentheses.

2020-07-24 Thread Ruslan Ermilov
On Sat, Jul 18, 2020 at 08:09:30PM +0800, balus wrote:
> # HG changeset patch
> # User balus  # Date 1595073121 -28800
> #      Sat Jul 18 19:52:01 2020 +0800
> # Node ID 92d9878c0c7549345f0a144cd81a6b6d45f21fc6
> # Parent  32a343635b50662979975e1204417bb1fc7e1b1f
> Core: enclosed parameters of macros in parentheses.

I'm going to commit the following updated patch:

# HG changeset patch
# User balus 
# Date 1595399139 -10800
#  Wed Jul 22 09:25:39 2020 +0300
# Node ID 827f61a45a12382773c4053e7858594c2ce611c0
# Parent  4f30f75dbdf33d6fae9e70086e0df5cbab7db027
Core: enclosed parameters of the ngx_buf.h macros in parentheses.

diff --git a/src/core/ngx_buf.h b/src/core/ngx_buf.h
--- a/src/core/ngx_buf.h
+++ b/src/core/ngx_buf.h
@@ -125,20 +125,20 @@ typedef struct {
 #define NGX_CHAIN_ERROR (ngx_chain_t *) NGX_ERROR
 
 
-#define ngx_buf_in_memory(b)(b->temporary || b->memory || b->mmap)
-#define ngx_buf_in_memory_only(b)   (ngx_buf_in_memory(b) && !b->in_file)
+#define ngx_buf_in_memory(b)   ((b)->temporary || (b)->memory || (b)->mmap)
+#define ngx_buf_in_memory_only(b)  (ngx_buf_in_memory(b) && !(b)->in_file)
 
 #define ngx_buf_special(b)   \
-((b->flush || b->last_buf || b->sync)\
- && !ngx_buf_in_memory(b) && !b->in_file)
+(((b)->flush || (b)->last_buf || (b)->sync)  \
+ && !ngx_buf_in_memory(b) && !(b)->in_file)
 
 #define ngx_buf_sync_only(b) \
-(b->sync \
- && !ngx_buf_in_memory(b) && !b->in_file && !b->flush && !b->last_buf)
+((b)->sync && !ngx_buf_in_memory(b)  \
+ && !(b)->in_file && !(b)->flush && !(b)->last_buf)
 
 #define ngx_buf_size(b)  \
-(ngx_buf_in_memory(b) ? (off_t) (b->last - b->pos):  \
-(b->file_last - b->file_pos))
+(ngx_buf_in_memory(b) ? (off_t) ((b)->last - (b)->pos):  \
+((b)->file_last - (b)->file_pos))
 
 ngx_buf_t *ngx_create_temp_buf(ngx_pool_t *pool, size_t size);
 ngx_chain_t *ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs);
@@ -149,8 +149,8 @@ ngx_chain_t *ngx_create_chain_of_bufs(ng
 
 ngx_chain_t *ngx_alloc_chain_link(ngx_pool_t *pool);
 #define ngx_free_chain(pool, cl) \
-cl->next = pool->chain;  \
-pool->chain = cl
+(cl)->next = (pool)->chain;  \
+(pool)->chain = (cl)
 
 
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: [PATCH] Core: enclosed parameters of macros in parentheses.

2020-07-24 Thread balus
Seems more comprehensive and the commit message is more accurate
now, thank you.


-- Original --
From:   
 "nginx-devel"  
  
http://mailman.nginx.org/mailman/listinfo/nginx-devel___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel