client.on() not handling/accepting requests when awaiting response from SQLite when it is busy
This is how I register events in index.ts
This code is run on "InteractionCreate" event
The first interaction gets received and runs
deferReply
and then execute(interaction, db)
But while the call to the database
is running inside the execute(interaction, db)
Any more slash command requests are not going through the client.on(Events.InteractionCreate, ...)
event handler. Only when the call to the database is finished it receives responses. I tried using sleep command to see if by stopping the interaction from executing, subsequent calls would be ignored or not, but they were not, all the InteractionCreate events were going through and deferred even though the previous one had not finished fully responding.
I use better-sqlite3
and kysely
query builder and orm.
database.ts
index.ts
4 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
- ✅
Marked as resolved by OPI use DB Browser for SQLite, portable program to lock the database and make it busy, but I don't want that to stop event handlers from executing, I want the handlers to execute and report that there was an error with the database.
It is inside try catch block and when the first event handler runs, it reports after 5 seconds
And during those 5 seconds, more calls are not handled by the handler
await interaction.deferReply({ ephemeral: false });
This does not run during those 5 seconds when I send a new slash command request, and because 3 seconds already pass, it fails when it starts handling after 5 seconds because it got expiredyou can't, really
better-sqlite3 is by design synchronous, and JS is single-threaded
you can turn the timeout down to 0 (? i assume that will work. you'd need to test it) by passing the appropriate option https://github.com/WiseLibs/better-sqlite3/blob/HEAD/docs/api.md#new-databasepath-options so it'll immediately throw
or you could run your queries in a worker thread, but that adds a lot of complexity
anyway this isn't really an issue with the package itself, so you could try asking in #other-js-ts if those options don't work for you
Thank you, that really helped, for now setting timeout to something less than 1 second will work for me. In the future I will at least know to use an asynchronous database. ❤️