Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Cannot use kong.db #13065

Closed
1 task done
123jixinyu opened this issue May 23, 2024 · 1 comment
Closed
1 task done

Cannot use kong.db #13065

123jixinyu opened this issue May 23, 2024 · 1 comment

Comments

@123jixinyu
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Kong version ($ kong version)

3.4 or 3.5 or 3.6

Current Behavior

During the development of custom Kong plugins, I found that I couldn't use kong.db to query entities. Whenever I executed kong.db.xxxx, the process would block, and the code could not proceed to the next step, though it could be used within ngx.timer.at. I have tried multiple versions of Kong, all with the same result. I am certain that I have taken the following measures:

1.Turned on the logging switch and set it to debug level.
2.Allowed in the execution phase, specifically in the access phase.
3.I tried using third-party libraries, such as luasql.postgres, which work perfectly.
4.The database is normal and connectable. I have checked the status API, and the database is accessible.

Demo

function handler:access(config)
    kong.log.info("accessing database")
    local entity, err = kong.db.entities:select({ id = "some-id" })
    if err then
        kong.log.err("Error accessing database: ", err)
        return kong.response.exit(500, { message = "Internal Server Error" })
    end

    if not entity then
        return kong.response.exit(404, { message = "Entity not found" })
    end
end

Expected Behavior

No response

Steps To Reproduce

No response

Anything else?

No response

@jeremyjpj0916
Copy link
Contributor

This an issue in 3.7.0 too? I think I have a custom plugin that used kong.db.* so this may be problematic for me too if it is the case. But don't other kong native plugins access the db in the access phase too? Wonder why they would all not be having major issues too if so.

@Kong Kong locked and limited conversation to collaborators Jul 15, 2024
@hanshuebner hanshuebner converted this issue into discussion #13375 Jul 15, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

3 participants