Hello, fellow Kong Community members.
While working on a custom plugin development, we noticed an abnormal execution order of the nginx phases. We were incrementing a shared variable’s value in the access phase which was later decremented during the log phase. We assumed that the access phase is always executed before the later phases of the request life cycle(header_filter/body_filter/log). But while testing the plugin we notice that the value of the shared variable became negative after a few random requests.
On investigating we observed that every time a request is made to a path that doesn’t exist (no route defined), all the phases of our global plugin are executed except for the access phase and this was the case with all the global plugins.
I tried to look at the Kong docs to check if contains an explanation or reasoning behind this but couldn’t find any.
Could you please tell me why this happens or can point me to the docs/GitHub code where this has been mentioned/handled?
Steps to reproduce(Assuming basic kong setup is available):
- Create a plugin “test-plugin” in the plugins folder
- In its handler.lua define the following phases - rewrite, access, header_filter, body_filter, log
- In each of the phase functions just log (kong.log.info(" is being executed")) to track if a phase has been executed
- Start kong
- Add the test-plugin as a global plugin using Konga or Admin API
- Open the kong error logs (/kong/servroot/logs)
- Now send a request to a random path (through Postman or browser) that doesn’t exist (eg. “/random123”)
Check the kong logs to see which phases have been executed. The logs will only print the statements from rewrite, header_filter, body_filter and log phases. The access phase doesn’t execute.