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: coroutine.wrap:20: API disabled in the context of log_by_lua error in Batch Processor #1181

Closed
sshniro opened this issue Mar 2, 2020 · 5 comments

Comments

@sshniro
Copy link
Member

sshniro commented Mar 2, 2020

Hi,

When using the batch processor inside the _M.log phase the system throws the following error.

This happens when I use core.schema.check(schema, config) inside the batch processor.
If I use a simple validation (if/else) then the workflow is working without an error.

2020/03/02 15:36:40 [error] 5155#5155: *237 failed to run log_by_lua*: coroutine.wrap:20: API disabled in the context of log_by_lua*
stack traceback:
	[C]: in function 'create'
	coroutine.wrap:20: in function '_get_loader'
	...one3/incubator-apisix//deps/share/lua/5.1/jsonschema.lua:197: in function 'create_obj_fun'
	...che/clone3/incubator-apisix/lua/apisix/core/lrucache.lua:66: in function 'cached_validator'
	...pache/clone3/incubator-apisix/lua/apisix/core/schema.lua:34: in function 'check'
	.../incubator-apisix/lua/apisix/plugins/batch-processor.lua:110: in function 'new'
	...lone3/incubator-apisix/lua/apisix/plugins/udp-logger.lua:118: in function 'phase_fun'
	/home/nirojan/apache/clone3/incubator-apisix/lua/apisix.lua:154: in function 'run_plugin'
	/home/nirojan/apache/clone3/incubator-apisix/lua/apisix.lua:459: in function 'http_log_phase'
	log_by_lua(nginx.conf:191):2: in main chunk while logging request, client: 127.0.0.1, server: , request: "GET /?param1=value HTTP/1.1", upstream: "http://127.0.0.1:80/?param1=value", host: "127.0.0.1:9080"

Is this a limitation? Some guidance would be helpful.

@sshniro
Copy link
Member Author

sshniro commented Mar 2, 2020

@membphis I guess APISIX is not allowing to access the JSON schema validator during log phase. Is this due to any performance gain? or shall I use normal validation instead of using the jsonschema?

@membphis
Copy link
Member

membphis commented Mar 3, 2020

In jsonschema, the compiled Lua code is generated by using yield, but the yield operation is not supported in log_phase.

I suggest modifying the https://github.com/iresty/jsonschema implementation to avoid using the yield method.

https://github.com/iresty/jsonschema/blob/ddd76d719cb102a0db2c44fe207745a9c3e53452/lib/jsonschema.lua#L141

@sshniro
Copy link
Member Author

sshniro commented Mar 12, 2020

I would like to start working on this issue, as it is blocking #965 and #1070 for batch processing. Will post the question in the associated repo.

@membphis
Copy link
Member

@sshniro api7/jsonschema#8

I have created an issue, if you would like to do this job, please leave a message on this issue. I will assign this issue to you.

@sshniro
Copy link
Member Author

sshniro commented Apr 28, 2020

Closing this issue, as it's fixed by #8

@sshniro sshniro closed this as completed Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants