Skip to content

Error async operation inside in r.subrequest with callback #287

@levonet

Description

@levonet

nginx throw errors after update version of njs to 0.3.8:
2020/02/10 16:18:29 [error] 144#144: *6947506 async operation inside "js_log" variable handler, client: nda, server: nda, request: "POST /nda HTTP/1.1", host: "nda"

r.subrequest continues to work. In documentation:

Since 0.3.8, if a callback is not provided, the Promise object that resolves to the subrequest response object is returned.

There should be no error if a function has a callback argument. I think so.

Here is a minimal case:

function js_log(r) {
    var log = {
        // ...
    };
    var args = {
        method: 'POST',
        body: JSON.stringify(log)
    };
    r.subrequest('/_log', args, (res) => {});
    return '1';
}

in conf:

js_set $x_js_log js_log;
server {
    location / {
        proxy_set_header X-Log $x_js_log;
        proxy_pass http://backend;
    }
    location = /_log {
        internal;
        return 200;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions