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

bug: mocking plugin panic when response_example contain $ #8810

Closed
yangxikun opened this issue Feb 7, 2023 · 5 comments
Closed

bug: mocking plugin panic when response_example contain $ #8810

yangxikun opened this issue Feb 7, 2023 · 5 comments
Labels

Comments

@yangxikun
Copy link
Contributor

Current Behavior

lua entry thread aborted, cause http 500 response.

Expected Behavior

Should not abort.

Error Logs

2023/02/06 16:20:21 [error] 52#52: *75286 lua entry thread aborted: runtime error: /usr/local/apisix-2.13.2/apisix/core/utils.lua:298: attempt to index upvalue '_ctx' (a nil value)
stack traceback:
coroutine 0:
	/usr/local/apisix-2.13.2/apisix/core/utils.lua: in function 'replace'
	/usr/local/openresty/lualib/resty/core/regex.lua:1003: in function 're_gsub'
	/usr/local/apisix-2.13.2/apisix/core/utils.lua:319: in function 'resolve_var'
	/usr/local/apisix-2.13.2/apisix/plugins/mocking.lua:221: in function 'phase_func'
	/usr/local/apisix-2.13.2/apisix/plugin.lua:748: in function 'run_plugin'
	/usr/local/apisix-2.13.2/apisix/init.lua:481: in function 'http_access_phase'
	access_by_lua(nginx.conf:300):2: in main chunk

Steps to Reproduce

config mocking like:

routes:
  -
    uri: /hello
    upstream:
      nodes:
        "127.0.0.1:1980": 1
      type: roundrobin
    plugins:
      mocking:
        response_example: '{"$a":1}'

Environment

  • APISIX version (run apisix version): master branch
  • Operating system (run uname -a):
  • OpenResty / Nginx version (run openresty -V or nginx -V):
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info):
  • APISIX Dashboard version, if relevant:
  • Plugin runner version, for issues related to plugin runners:
  • LuaRocks version, for installation issues (run luarocks --version):
@yangxikun
Copy link
Contributor Author

The bug code line:

return conf.response_status, core.utils.resolve_var(response_content)

Should call core.utils.resolve_var(response_content, ctx.var).

@monkeyDluffy6017
Copy link
Contributor

I think you are right, would you like to fix this and add some test cases ?

@yangxikun
Copy link
Contributor Author

Ok, Let me try.

hongbinhsu added a commit to fitphp/apix that referenced this issue Feb 13, 2023
* upstream/master:
  docs: change the file name to 'create-ssl.py'.If 'ssl.py' is used as … (apache#8623)
  feat: Body transformer plugin (apache#8766)
  fix: mocking plugin panic when response_example contain $ (apache#8810) (apache#8816)
  feat: file logger plugin support response body in variable (apache#8711)
  docs(getting-started): rewrite the install section (apache#8807)
  feat: allow each logger to define custom log format in its conf (apache#8806)
  fix(etcd): reloaded data may be in res.body.node (apache#8736)
  fix: fix fetch all service info from consul (apache#8651)
  docs: fix global-rule.md wrong curl  address (apache#8793)
  feat: stream subsystem support consul service discovery (apache#8696)
  chore(kafka-logger): support configuration `meta_refresh_interval` parameter (apache#8762)
  feat: ready to release 2.15.2 (apache#8783)
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 Jan 24, 2024
Copy link

github-actions bot commented Feb 7, 2024

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 Feb 7, 2024
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

2 participants