Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request help: no cors header return sometimes #3407

Closed
rogerogers opened this issue Jan 25, 2021 · 18 comments
Closed

request help: no cors header return sometimes #3407

rogerogers opened this issue Jan 25, 2021 · 18 comments
Labels

Comments

@rogerogers
Copy link
Contributor

no cors header return sometimes

Environment

  • apisix version: 2.2
  • OS: Linux localhost.localdomain 5.9.13-200.fc33.x86_64 change: added doc of how to load plugin. #1 SMP Tue Dec 8 15:42:52 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux fedora 33
  • OpenResty / Nginx version: nginx version: openresty/1.19.3.1
    built by gcc 10.2.1 20201016 (Red Hat 10.2.1-6) (GCC)
    built with OpenSSL 1.1.1h 22 Sep 2020 (running with OpenSSL 1.1.1i 8 Dec 2020)

Minimal test code / Steps to reproduce the issue

  1. wrong header
    image

  2. right header
    image

my cors config in a service group
{ "allow_credential": true, "allow_headers": "DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,Arg-Id", "allow_methods": "GET,POST,OPTIONS", "allow_origins": "http://m-local.guess.com,http://www-local.guess.com", "disable": false, "expose_headers": "Authorization" }

@spacewander
Copy link
Member

I can't see the word in your images.
You need to provide reproducible steps in text.

@rogerogers
Copy link
Contributor Author

I can't see the word in your images.
You need to provide reproducible steps in text.

It's just a browser request list, sometime no cors header return, but not always. like this
HTTP/1.1 200 OK Server: openresty Date: Mon, 25 Jan 2021 05:32:58 GMT Content-Type: text/plain; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive

@spacewander
Copy link
Member

What you said is not a reproducible steps. I can't follow your word to create an environment to reproduce the issue, so I can't help you to solve the problem.

@spacewander
Copy link
Member

For the "sometimes" problem, you should add more log in the cors plugin, to see what happened when the error occurs.
For example:

local multiple_origin, err = core.lrucache.plugin_ctx(lrucache, ctx, nil,

You should log down the ctx.conf_type, ctx.conf_id and returned multiple_origin.

@tokers
Copy link
Contributor

tokers commented Jan 25, 2021

@rogerogers Also, the configuration like Route, Upstream of APISIX should be provided here.

@rogerogers
Copy link
Contributor Author

@rogerogers Also, the configuration like Route, Upstream of APISIX should be provided here.

Here is the metadata in etcd

  • service {"id":"338649582328091268","create_time":1611380480,"update_time":1611544897,"name":"api-local","upstream_id":"338680447942791812","plugins":{"cors":{"allow_credential":true,"allow_headers":"DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,Arg-Id","allow_methods":"GET,POST,OPTIONS","allow_origins":"http://m-local.guess.com,http://www-local.guess.com","disable":false,"expose_headers":"Authorization"}}}
  • route {"id":"338680561356771972","create_time":1611398945,"update_time":1611543793,"uris":["/*"],"name":"api-local","methods":["GET","HEAD","POST","PUT","DELETE","OPTIONS","PATCH"],"hosts":["api-local.guess.com"],"vars":[],"service_id":"338649582328091268","upstream_id":"338680447942791812","status":1}

@rogerogers
Copy link
Contributor Author

rogerogers commented Jan 26, 2021

For the "sometimes" problem, you should add more log in the cors plugin, to see what happened when the error occurs.
For example:

local multiple_origin, err = core.lrucache.plugin_ctx(lrucache, ctx, nil,

You should log down the ctx.conf_type, ctx.conf_id and returned multiple_origin.

code

  • local multiple_origin, err = core.lrucache.plugin_ctx(lrucache, ctx, nil,
                                                  create_multiple_origin_cache, conf)
    local json=require('cjson.safe')
    core.log.error(json.encode(multiple_origin))
    
  • local allow_methods = conf.allow_methods
    core.log.error(conf.allow_methods.. 'guess')
    if allow_methods == "**" then
        allow_methods = "GET,POST,PUT,DELETE,PATCH,HEAD,OPTIONS,CONNECT,TRACE"
    end
    core.response.set_header("Access-Control-Allow-Origin", ctx.cors_allow_origins)
    core.log.error(ctx.cors_allow_origins)
    

logs

Seems no log when situation occurred

@spacewander
Copy link
Member

Seems no log when situation occurred

So you mean when error occurs, the header_filter in cors plugin is not run?
Interesting, I have not seen this before. Maybe you can add more logs to find its execution path (or decrease the log level to info if permitted).

@jinyuxiaoqiang
Copy link

Have you solved this problem? I meet the same problem

@jinyuxiaoqiang
Copy link

Seems no log when situation occurred

So you mean when error occurs, the header_filter in cors plugin is not run? Interesting, I have not seen this before. Maybe you can add more logs to find its execution path (or decrease the log level to info if permitted).

I add log to the cors plugin, when the error occurred _M.rewrite will run. _M.header_filter and set headers not run @spacewander

@spacewander
Copy link
Member

@jinyuxiaoqiang
What's your APISIX version?
Is there a way to 100% reproduce it?

@jinyuxiaoqiang
Copy link

apisix version: 2.2
It reproduced rapidly yesterday,even I restart apisix service. At last I restart dashboard-2.3.0 and apisix service,it returns to normal. I will keep looking on it. Still there isn’t a way to 100% reproduce it.

@jinyuxiaoqiang
Copy link

I have reproduced this problem.After create global_plugin through dashboard, I delete this global_plugin.It remains something in etcd,then the problem will sometime occurred.

/global_rules/1
{"id":"1","plugins":{}}

@spacewander
Copy link
Member

@bzp2010
Has this issue been reported to dashboard before?
Maybe it is relative to #4867

@jinyuxiaoqiang
Copy link

I can’t figure out how it leads to the problem. Can you give me some instructions?

@spacewander
Copy link
Member

Can this be reproduced with APISIX 2.9 or higher?

@github-actions
Copy link

This issue has been marked as stale due to 350 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

@github-actions github-actions bot added the stale label Nov 21, 2022
@github-actions
Copy link

github-actions bot commented Dec 6, 2022

This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants