Repository navigation
Closed
Description
I'm seeing a strange error. I dropped @fractaledmind a note and he suggested I post here.
W, [2024-09-05T18:49:32.074281 #809854] WARN -- : SolidQueue-0.3.4 Error deregistering Supervisor (1.1ms) process_id: 68, pid: 564289, hostname: "HOST", last_heartbeat_at: Sat, 31 Aug 2024 15:16:55.474066000 UTC +00:00, claimed_size: 0, pruned: {:process=>#<SolidQueue::Process id: 68>, :pruned=>true, :claimed_size=>0, :error=>#<ActiveRecord::StatementInvalid: SQLite3::CorruptException: database disk image is malformed>, :exception=>["ActiveRecord::StatementInvalid", "SQLite3::CorruptException: database disk image is malformed"], :exception_object=>#<ActiveRecord::StatementInvalid: SQLite3::CorruptException: database disk image is malformed>}, error: "ActiveRecord::StatementInvalid SQLite3::CorruptException: database disk image is malformed"
In sqlite3 client.
sqlite> .open production-queue.sqlite3
sqlite> pragma integrity_check;
*** in database main ***
On tree page 523 cell 23: Rowid 146 out of order
NULL value in solid_queue_jobs.created_at
NULL value in solid_queue_jobs.updated_at
row 146 missing from index index_solid_queue_jobs_for_alerting
row 146 missing from index index_solid_queue_jobs_for_filtering
row 146 missing from index index_solid_queue_jobs_on_finished_at
row 146 missing from index index_solid_queue_jobs_on_active_job_id
row 146 missing from index index_solid_queue_jobs_on_class_name
NULL value in solid_queue_jobs.created_at
NULL value in solid_queue_jobs.updated_at
row 147 missing from index index_solid_queue_jobs_for_alerting
row 147 missing from index index_solid_queue_jobs_for_filtering
row 147 missing from index index_solid_queue_jobs_on_finished_at
row 147 missing from index index_solid_queue_jobs_on_active_job_id
row 147 missing from index index_solid_queue_jobs_on_class_name
NULL value in solid_queue_jobs.created_at
NULL value in solid_queue_jobs.updated_at
row 148 missing from index index_solid_queue_jobs_for_alerting
row 148 missing from index index_solid_queue_jobs_for_filtering
row 148 missing from index index_solid_queue_jobs_on_finished_at
row 148 missing from index index_solid_queue_jobs_on_active_job_id
row 148 missing from index index_solid_queue_jobs_on_class_name
NULL value in solid_queue_jobs.created_at
NULL value in solid_queue_jobs.updated_at
row 149 missing from index index_solid_queue_jobs_for_alerting
row 149 missing from index index_solid_queue_jobs_for_filtering
row 149 missing from index index_solid_queue_jobs_on_finished_at
row 149 missing from index index_solid_queue_jobs_on_active_job_id
row 149 missing from index index_solid_queue_jobs_on_class_name
Error: stepping, database disk image is malformed (11)
sqlite> pragma integrity_check;
*** in database main ***
On tree page 523 cell 23: Rowid 146 out of order
NULL value in solid_queue_jobs.created_at
NULL value in solid_queue_jobs.updated_at
row 146 missing from index index_solid_queue_jobs_for_alerting
row 146 missing from index index_solid_queue_jobs_for_filtering
row 146 missing from index index_solid_queue_jobs_on_finished_at
row 146 missing from index index_solid_queue_jobs_on_active_job_id
row 146 missing from index index_solid_queue_jobs_on_class_name
Error: stepping, database disk image is malformed (11)
Doing a .clone doesn't seem to fix.
I'm not in "real" production and this is a job queue and thus somewhat destroyable, so I'm going to take that approach.
I've also seen similar corruption on my local development environment too akin to that mentioned by @marcoroth on X.
In that case I just destroyed and recreated the file and moved on.
Metadata
Metadata
Assignees
Labels
No labels
Activity
marcoroth commentedon Sep 5, 2024
Yes, this is excactly what I was seeing as well. Thanks for opening the issue and tagging me @andycroll as I wanted to open an issue for this too 🙌🏼
This happened to me in this open source repo: http://github.com/adrienpoly/rubyvideo
You can easily reproduce it by running
rails sas a separate process and doing a double Ctrl-C in quick succession.I think it only happens with the Puma Plugin from what I could tell.
andycroll commentedon Sep 5, 2024
In production, I'm running as a separate worker, not the puma plugin.
rosa commentedon Sep 5, 2024
Ohhh! See also #294, where @wdiechmann provided some advice in the last comment, which I'm not sure if it applies to your case.
The Puma plugin detail is quite interesting! Did you manage to reproduce only with that?
rosa commentedon Sep 5, 2024
Ah, sorry, just reread and I see @andycroll's error happened when running just the supervisor separately 🤔
Do you know what happened right before that?
andycroll commentedon Sep 5, 2024
In my case a deploy (on a Hatchbox managed server) so killing the worker process was certainly happening when the error started.
rosa commentedon Sep 5, 2024
It's also very surprising to me that you can corrupt a database with only Active Record and quite regular queries 🤔
I wouldn't know how to cause this on purpose 😅 A row missing from an index? 🤔
I'll use @marcoroth's instructions to reproduce and see if I can find out what's going on!
fractaledmind commentedon Sep 5, 2024
I haven't been able to dig in myself yet, but after reading this: https://www.sqlite.org/howtocorrupt.html and knowing the bits that I know about the supervisor architecture, I was first drawn to:
marcoroth commentedon Sep 5, 2024
If it helps, here's how my
pragma integrity_checklooks like:rosa commentedon Sep 5, 2024
Ohhhh, thanks a lot @fractaledmind. That'd make perfect sense as the culprit! I thought Rails would handle this properly and wouldn't reuse the same connection but I need to dig more.
fractaledmind commentedon Sep 5, 2024
Yeah, this sounds like it might be what is occurring:
rosa commentedon Sep 6, 2024
The reason I thought that were these PRs that I had looked at in the past, because of another error (not as serious as this one) that someone reported with PostgreSQL 🤔
There must be something else going on here.
fractaledmind commentedon Sep 6, 2024
No idea yet if this is related, but rails/rails#31173 has this in the description:
And no
discard!method is defined (in that PR or currently) for the SQLite3 AR adapterrosa commentedon Sep 6, 2024
Thanks @fractaledmind! I see this code has changed quite a lot since these PRs, (for example rails/rails#37296), so I was trying to understand how everything worked... That comment caught my attention too but I honestly wasn't sure why "there is no server to confuse" makes SQLite immune to this problem 😳
@marcoroth, I've been trying to reproduce the problem following your steps but I can't. I have to say I have upgraded Solid Queue in rubyvideo to version 0.8.2 as it was using a quite old version so maybe there's something else at play there.
rosa commentedon Sep 6, 2024
Tried without upgrading and same thing... I can't manage to reproduce it by starting the app with
rails sand then Ctrl + C, double, in quick succession 😕rosa commentedon Sep 6, 2024
I've also tried to artificially delay the jobs that are being run (in particular,
MeiliSearch::Rails::MSJob, that were failing because I don't have Meilisearch running, so they were failing very fast) by adding some sleeps there, and still same behaviour. I don't manage to corrupt the file.59 remaining items
flavorjones commentedon Sep 16, 2024
Changed direction, here's the latest plan, I'd love feedback:
flavorjones commentedon Sep 18, 2024
@andycroll @marcoroth @fractaledmind I just cut a release candidate of sqlite3-ruby with the fork-safety changes from sparklemotion/sqlite3-ruby#558:
It's an invasive change, it's been a hard issue to reproduce, and it's challenging to test every possible scenario ... so I would really like to have some folks use it and see if we can find problems and/or build confidence.
I've tried out the
solid_queue_bughuntrepo and it seems like it's working OK (and I can see the warning messages from sqlite3-ruby in the log which means it's doing something ✔). But the more scenarios we can test with the better. If you could just drop a note here if you've been able to test (or if you intend to test), I would ❤️ you forever.flavorjones commentedon Sep 19, 2024
Released https://github.com/sparklemotion/sqlite3-ruby/releases/tag/v2.1.0.rc2 addressing a performance regression in rc1.
adrienpoly commentedon Sep 23, 2024
FYI I have upgraded rubyvideo.dev with this latest version(rubyevents/rubyevents@71ece9b). It is now live in prod. So fare everything looks perfect.
npezza93 commentedon Sep 24, 2024
Been using the new sqlite rc version and havent had any issues. But when running
bin/jobs starti'm seeing:Should i be seeing that warning with this config?
I have a database config of
And a queue.yml of
flavorjones commentedon Sep 24, 2024
@npezza93 I think it's normal to see this message. I'm not a solid queue expert, but I believe the supervisor process hits the database (as part of active record bootstrapping if nothing else) before forking, and that would result in a warning on your tty. Someone who knows it better might be able to tell me how I'm wrong.
Sqlite3-ruby maintainers discussed whether or not to emit warnings, but we decided to err on the side of overcommunicating, at least in the RC and probably the first final release of 2.1.0.
dhh commentedon Sep 24, 2024
@flavorjones Maybe we can set a flag for Rails 8 to suppress that warning? Because would be nice if out of the box there is nothing alarming posted about the default setup. Especially since we still have some ways to go to reassure folks that sqlite is good and safe in production.
flavorjones commentedon Sep 24, 2024
@dhh Yep. We can add a method
SQLite3::ForkSafety.suppress_warnings!that will hush it up, and it can be called in the sqlite3 adapter. Hang tight.flavorjones commentedon Sep 24, 2024
See sparklemotion/sqlite3-ruby#566
flavorjones commentedon Sep 24, 2024
Also see rails/rails#53033
dhh commentedon Sep 24, 2024
Perfect, @flavorjones 👌
rosa commentedon Sep 25, 2024
Yes, that's exactly right! It uses the DB to register itself, which happens before forking. It's useful to have the supervisor registered before because, in that way, the other processes can register themselves knowing their
supervisor_id(from registering the supervisor).I haven't had time in the last few days, but I hope to address this in Solid Queue as well, closing the connections before forking.
northeastprince commentedon Sep 29, 2024
Does sparklemotion/sqlite3-ruby#558 close this?
dhh commentedon Sep 29, 2024
Yes.