solid_queue: SQLite3::BusyException: database is locked

not sure why I must put my foot into every rabbit hole along the way - but this one I’m yet to observe 😮

Context: hitting /notifications in the browser and then tap one of the notifications which will do a GET /notifications/:id updating the notification as unread and return head :ok (and turbo_stream a remove from the list of notifications ‘on the side’) slapped me in the face with this log(snippet)

13:29:20 web.1  | [ActionCable] [User 10] Finished "/cable" [WebSocket] for 127.0.0.1 at 2024-08-29 13:29:20 +0200
13:29:20 web.1  | [ActionCable] [User 10] Turbo::StreamsChannel stopped streaming from 10_noticed/notifications
13:29:20 web.1  | Started GET "/assets/turbo.min-0fdcb030.js.map" for 127.0.0.1 at 2024-08-29 13:29:20 +0200
13:29:20 web.1  | Started GET "/assets/stimulus.min-2395e199.js.map" for 127.0.0.1 at 2024-08-29 13:29:20 +0200
13:29:20 web.1  | Started GET "/cable" for 127.0.0.1 at 2024-08-29 13:29:20 +0200
13:29:20 web.1  | Started GET "/cable" [WebSocket] for 127.0.0.1 at 2024-08-29 13:29:20 +0200
13:29:20 web.1  | Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
13:29:20 web.1  | [writer]   User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 10], ["LIMIT", 1]]
13:29:20 web.1  | [writer]   ↳ app/channels/application_cable/connection.rb:23:in `find_verified_user'
13:29:20 web.1  | [ActionCable] [User 10] Registered connection (Z2lkOi8vbW9ydGltZXIvVXNlci8xMA)
13:29:20 web.1  | [ActionCable] [User 10] [writer]   Account Load (0.1ms)  SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = ? LIMIT ?  [["id", 25], ["LIMIT", 1]]
13:29:20 web.1  | [ActionCable] [User 10] [writer]   ↳ app/models/current.rb:16:in `user='
13:29:20 web.1  | [ActionCable] [User 10] ActionCable: Current.user info@mortimer.pro -----------------------------
13:29:20 web.1  | [ActionCable] [User 10] Turbo::StreamsChannel is transmitting the subscription confirmation
13:29:20 web.1  | [ActionCable] [User 10] Turbo::StreamsChannel is streaming from 10_noticed/notifications
13:29:55 web.1  | Started GET "/notifications" for 127.0.0.1 at 2024-08-29 13:29:55 +0200
13:29:55 web.1  | Processing by NotificationsController#index as HTML
13:29:55 web.1  | [reader]   User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 10], ["LIMIT", 1]]
13:29:55 web.1  | [reader]   Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = ? LIMIT ?  [["id", 25], ["LIMIT", 1]]
13:29:55 web.1  | [reader]   ↳ app/models/current.rb:16:in `user='
13:29:55 web.1  | [reader]   Filter Load (0.0ms)  SELECT "filters".* FROM "filters" WHERE "filters"."account_id" = ? AND "filters"."view" = ? LIMIT ?  [["account_id", 25], ["view", "notifications"], ["LIMIT", 1]]
13:29:55 web.1  | [reader]   ↳ app/controllers/concerns/resourceable.rb:73:in `set_filter'
13:29:55 web.1  |   Rendering layout layouts/application.html.erb
13:29:55 web.1  |   Rendering notifications/index.html.erb within layouts/application
13:29:55 web.1  | [reader]   Noticed::Notification Load (0.1ms)  SELECT "noticed_notifications".* FROM "noticed_notifications" WHERE "noticed_notifications"."recipient_id" = ? AND "noticed_notifications"."recipient_type" = ? AND "noticed_notifications"."read_at" IS NULL ORDER BY "noticed_notifications"."created_at" DESC  [["recipient_id", 10], ["recipient_type", "User"]]
13:29:55 web.1  | [reader]   ↳ app/views/notifications/index.html.erb:6
13:29:55 web.1  | [reader]   Noticed::Event Load (0.0ms)  SELECT "noticed_events".* FROM "noticed_events" WHERE "noticed_events"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
13:29:55 web.1  | [reader]   ↳ app/views/notifications/_notification.html.erb:2
13:29:55 web.1  |   Rendered notifications/_notification.html.erb (Duration: 6.1ms | GC: 0.4ms)
13:29:55 web.1  |   Rendered notifications/index.html.erb within layouts/application (Duration: 19.6ms | GC: 0.9ms)
13:29:55 web.1  |   Rendered layouts/_generic_header.html.erb (Duration: 0.3ms | GC: 0.0ms)
13:29:55 web.1  | [reader]   ActiveStorage::Attachment Load (0.0ms)  SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = ? AND "active_storage_attachments"."record_type" = ? AND "active_storage_attachments"."name" = ? LIMIT ?  [["record_id", 25], ["record_type", "Account"], ["name", "logo"], ["LIMIT", 1]]
13:29:55 web.1  | [reader]   ↳ app/views/components/navigation_component.rb:28:in `block (5 levels) in view_template'
13:29:55 web.1  | [reader]   Noticed::Notification Exists? (0.1ms)  SELECT 1 AS one FROM "noticed_notifications" WHERE "noticed_notifications"."recipient_id" = ? AND "noticed_notifications"."recipient_type" = ? AND "noticed_notifications"."read_at" IS NULL LIMIT ?  [["recipient_id", 10], ["recipient_type", "User"], ["LIMIT", 1]]
13:29:55 web.1  | [reader]   ↳ app/views/components/notification_bell.rb:4:in `initialize'
13:29:55 web.1  | [reader]   ActiveStorage::Attachment Load (0.0ms)  SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = ? AND "active_storage_attachments"."record_type" = ? AND "active_storage_attachments"."name" = ? LIMIT ?  [["record_id", 10], ["record_type", "User"], ["name", "mugshot"], ["LIMIT", 1]]
13:29:55 web.1  | [reader]   ↳ app/views/components/navigation_component.rb:171:in `block (3 levels) in profile_dropdown'
13:29:55 web.1  |   Rendered layout layouts/application.html.erb (Duration: 22.8ms | GC: 1.2ms)
13:29:55 web.1  | Completed 200 OK in 79ms (Views: 22.9ms | ActiveRecord: 0.6ms (8 queries, 0 cached) | GC: 1.6ms)
13:29:55 web.1  | 
13:29:55 web.1  | 
13:29:55 web.1  | [ActionCable] [User 10] Finished "/cable" [WebSocket] for 127.0.0.1 at 2024-08-29 13:29:55 +0200
13:29:55 web.1  | [ActionCable] [User 10] Turbo::StreamsChannel stopped streaming from 10_noticed/notifications
13:29:55 web.1  | Started GET "/assets/turbo.min-0fdcb030.js.map" for 127.0.0.1 at 2024-08-29 13:29:55 +0200
13:29:55 web.1  | Started GET "/assets/stimulus.min-2395e199.js.map" for 127.0.0.1 at 2024-08-29 13:29:55 +0200
13:29:55 web.1  | Started GET "/cable" for 127.0.0.1 at 2024-08-29 13:29:55 +0200
13:29:55 web.1  | Started GET "/cable" [WebSocket] for 127.0.0.1 at 2024-08-29 13:29:55 +0200
13:29:55 web.1  | Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
13:29:55 web.1  | [writer]   User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 10], ["LIMIT", 1]]
13:29:55 web.1  | [writer]   ↳ app/channels/application_cable/connection.rb:23:in `find_verified_user'
13:29:55 web.1  | [ActionCable] [User 10] Registered connection (Z2lkOi8vbW9ydGltZXIvVXNlci8xMA)
13:29:55 web.1  | [ActionCable] [User 10] [writer]   Account Load (0.1ms)  SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = ? LIMIT ?  [["id", 25], ["LIMIT", 1]]
13:29:55 web.1  | [ActionCable] [User 10] [writer]   ↳ app/models/current.rb:16:in `user='
13:29:55 web.1  | [ActionCable] [User 10] ActionCable: Current.user info@mortimer.pro -----------------------------
13:29:55 web.1  | [ActionCable] [User 10] Turbo::StreamsChannel is transmitting the subscription confirmation
13:29:55 web.1  | [ActionCable] [User 10] Turbo::StreamsChannel is streaming from 10_noticed/notifications
13:30:00 web.1  | [ActiveJob] [writer]   TRANSACTION (0.1ms)  begin transaction
13:30:00 web.1  | [ActiveJob] [writer]   SolidQueue::Job Create (0.2ms)  INSERT INTO "solid_queue_jobs" ("queue_name", "class_name", "arguments", "priority", "active_job_id", "scheduled_at", "finished_at", "concurrency_key", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING "id"  [["queue_name", "default"], ["class_name", "BackgroundManagerJob"], ["arguments", "{\"job_class\":\"BackgroundManagerJob\",\"job_id\":\"afdc0f30-1e2a-4864-9bf2-a9b76c119bea\",\"provider_job_id\":null,\"queue_name\":\"default\",\"priority\":null,\"arguments\":[],\"executions\":0,\"exception_executions\":{},\"locale\":\"da\",\"timezone\":\"UTC\",\"enqueued_at\":\"2024-08-29T11:30:00.043401000Z\",\"scheduled_at\":\"2024-08-29T11:30:00.043151000Z\"}"], ["priority", 0], ["active_job_id", "afdc0f30-1e2a-4864-9bf2-a9b76c119bea"], ["scheduled_at", "2024-08-29 11:30:00.043151"], ["finished_at", nil], ["concurrency_key", "[FILTERED]"], ["created_at", "2024-08-29 11:30:00.050224"], ["updated_at", "2024-08-29 11:30:00.050224"]]
13:30:00 web.1  | [ActiveJob] [writer]   TRANSACTION (0.0ms)  SAVEPOINT active_record_1
13:30:00 web.1  | [ActiveJob] [writer]   SolidQueue::Job Load (0.1ms)  SELECT "solid_queue_jobs".* FROM "solid_queue_jobs" WHERE "solid_queue_jobs"."id" = ? LIMIT ?  [["id", 5684], ["LIMIT", 1]]
13:30:00 web.1  | [ActiveJob] [writer]   SolidQueue::ReadyExecution Create (0.2ms)  INSERT INTO "solid_queue_ready_executions" ("job_id", "queue_name", "priority", "created_at") VALUES (?, ?, ?, ?) RETURNING "id"  [["job_id", 5684], ["queue_name", "default"], ["priority", 0], ["created_at", "2024-08-29 11:30:00.061360"]]
13:30:00 web.1  | [ActiveJob] [writer]   TRANSACTION (0.0ms)  RELEASE SAVEPOINT active_record_1
13:30:00 web.1  | [ActiveJob] Enqueued BackgroundManagerJob (Job ID: afdc0f30-1e2a-4864-9bf2-a9b76c119bea) to SolidQueue(default)
13:30:00 web.1  | [writer]   SolidQueue::RecurringExecution Insert (0.1ms)  INSERT INTO "solid_queue_recurring_executions" ("job_id","task_key","run_at","created_at") VALUES (5684, 'background_job_scheduler', '2024-08-29 11:30:00', STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')) ON CONFLICT ("task_key","run_at") DO NOTHING RETURNING "id"
13:30:00 web.1  | [writer]   TRANSACTION (0.1ms)  commit transaction
13:30:00 web.1  | SolidQueue-0.5.0 Enqueued recurring task (59.6ms)  task: "background_job_scheduler", active_job_id: "afdc0f30-1e2a-4864-9bf2-a9b76c119bea", at: "2024-08-29T11:30:00Z"
13:30:00 web.1  | [writer]   SolidQueue::Job Load (0.0ms)  SELECT "solid_queue_jobs".* FROM "solid_queue_jobs" WHERE "solid_queue_jobs"."id" = ? LIMIT ?  [["id", 5684], ["LIMIT", 1]]
13:30:00 web.1  | [ActiveJob] [BackgroundManagerJob] [afdc0f30-1e2a-4864-9bf2-a9b76c119bea] Performing BackgroundManagerJob (Job ID: afdc0f30-1e2a-4864-9bf2-a9b76c119bea) from SolidQueue(default) enqueued at 2024-08-29T11:30:00.043401000Z
13:30:00 web.1  | [ActiveJob] [BackgroundManagerJob] [afdc0f30-1e2a-4864-9bf2-a9b76c119bea] Performed BackgroundManagerJob (Job ID: afdc0f30-1e2a-4864-9bf2-a9b76c119bea) from SolidQueue(default) in 0.61ms
13:30:00 web.1  | [writer]   TRANSACTION (0.0ms)  begin transaction
13:30:00 web.1  | [writer]   SolidQueue::Job Update (0.9ms)  UPDATE "solid_queue_jobs" SET "updated_at" = ?, "finished_at" = ? WHERE "solid_queue_jobs"."id" = ?  [["updated_at", "2024-08-29 11:30:00.160812"], ["finished_at", "2024-08-29 11:30:00.160812"], ["id", 5684]]
13:30:00 web.1  | [writer]   SolidQueue::ClaimedExecution Destroy (0.0ms)  DELETE FROM "solid_queue_claimed_executions" WHERE "solid_queue_claimed_executions"."id" = ?  [["id", 5863]]
13:30:00 web.1  | [writer]   TRANSACTION (0.1ms)  commit transaction
13:30:00 web.1  | [writer]   TRANSACTION (0.1ms)  begin transaction
13:30:00 web.1  | [writer]   SolidQueue::Process Update (1.0ms)  UPDATE "solid_queue_processes" SET "last_heartbeat_at" = ? WHERE "solid_queue_processes"."id" = ?  [["last_heartbeat_at", "2024-08-29 11:30:00.223904"], ["id", 1032]]
13:30:00 web.1  | [writer]   TRANSACTION (0.0ms)  commit transaction
13:30:00 web.1  | [writer]   TRANSACTION (0.1ms)  begin transaction
13:30:00 web.1  | [writer]   SolidQueue::Process Update (7.5ms)  UPDATE "solid_queue_processes" SET "last_heartbeat_at" = ? WHERE "solid_queue_processes"."id" = ?  [["last_heartbeat_at", "2024-08-29 11:30:00.274049"], ["id", 1033]]
13:30:00 web.1  | [writer]   TRANSACTION (0.1ms)  commit transaction
13:30:00 web.1  | [writer]   TRANSACTION (11.5ms)  begin transaction
13:30:00 web.1  | [writer]   SolidQueue::Process Update (12.1ms)  UPDATE "solid_queue_processes" SET "last_heartbeat_at" = ? WHERE "solid_queue_processes"."id" = ?  [["last_heartbeat_at", "2024-08-29 11:30:00.275201"], ["id", 1034]]
13:30:00 web.1  | [writer]   TRANSACTION (0.0ms)  commit transaction
13:30:01 web.1  | Started GET "/notifications/1" for 127.0.0.1 at 2024-08-29 13:30:01 +0200
13:30:01 web.1  | Processing by NotificationsController#show as TURBO_STREAM
13:30:01 web.1  |   Parameters: {"id"=>"1"}
13:30:01 web.1  | [reader]   User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 10], ["LIMIT", 1]]
13:30:01 web.1  | [reader]   Account Load (0.0ms)  SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = ? LIMIT ?  [["id", 25], ["LIMIT", 1]]
13:30:01 web.1  | [reader]   ↳ app/models/current.rb:16:in `user='
13:30:01 web.1  | [reader]   Noticed::Notification Load (0.1ms)  SELECT "noticed_notifications".* FROM "noticed_notifications" WHERE "noticed_notifications"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
13:30:01 web.1  | [reader]   ↳ app/controllers/concerns/resourceable.rb:25:in `set_resource'
13:30:01 web.1  | Unpermitted parameter: :id. Context: { controller: NotificationsController, action: show, request: #<ActionDispatch::Request:0x000000010a226cc0>, params: {"controller"=>"notifications", "action"=>"show", "id"=>"1"} }
13:30:01 web.1  | Unpermitted parameter: :id. Context: { controller: NotificationsController, action: show, request: #<ActionDispatch::Request:0x000000010a226cc0>, params: {"controller"=>"notifications", "action"=>"show", "id"=>"1"} }
13:30:01 web.1  | [writer]   TRANSACTION (0.1ms)  begin transaction
13:30:01 web.1  | [writer]   ↳ app/controllers/notifications_controller.rb:30:in `mark_read'
13:30:01 web.1  | [writer]   CompletedEmployeeNotifier::Notification Update (0.6ms)  UPDATE "noticed_notifications" SET "read_at" = ?, "updated_at" = ? WHERE "noticed_notifications"."id" = ?  [["read_at", "2024-08-29 11:30:01.464675"], ["updated_at", "2024-08-29 11:30:01.464960"], ["id", 1]]
13:30:01 web.1  | [writer]   ↳ app/controllers/notifications_controller.rb:30:in `mark_read'
13:30:01 web.1  | [writer]   User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ?  [["id", 10], ["LIMIT", 1]]
13:30:01 web.1  | [writer]   ↳ app/models/concerns/noticed/notification_extensions.rb:15:in `broadcast_update_to_bell'
13:30:04 web.1  | Started GET "/notifications/1" for 127.0.0.1 at 2024-08-29 13:30:04 +0200
13:30:04 web.1  | Processing by NotificationsController#show as TURBO_STREAM
13:30:04 web.1  |   Parameters: {"id"=>"1"}
13:30:04 web.1  | [reader]   User Load (0.9ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ?  [["id", 10], ["LIMIT", 1]]
13:30:04 web.1  | [reader]   Account Load (0.2ms)  SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = ? LIMIT ?  [["id", 25], ["LIMIT", 1]]
13:30:04 web.1  | [reader]   ↳ app/models/current.rb:16:in `user='
13:30:04 web.1  | [reader]   Noticed::Notification Load (0.0ms)  SELECT "noticed_notifications".* FROM "noticed_notifications" WHERE "noticed_notifications"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
13:30:04 web.1  | [reader]   ↳ app/controllers/concerns/resourceable.rb:25:in `set_resource'
13:30:04 web.1  | Unpermitted parameter: :id. Context: { controller: NotificationsController, action: show, request: #<ActionDispatch::Request:0x000000010afc00c0>, params: {"controller"=>"notifications", "action"=>"show", "id"=>"1"} }
13:30:04 web.1  | Unpermitted parameter: :id. Context: { controller: NotificationsController, action: show, request: #<ActionDispatch::Request:0x000000010afc00c0>, params: {"controller"=>"notifications", "action"=>"show", "id"=>"1"} }
13:30:06 web.1  | [ActiveJob] [writer]   TRANSACTION (5001.5ms)  begin transaction
13:30:06 web.1  | [ActiveJob] [writer]   ↳ app/models/concerns/noticed/notification_extensions.rb:14:in `broadcast_update_to_bell'
13:30:06 web.1  | [ActiveJob] [writer]   SolidQueue::Job Create (5004.0ms)  INSERT INTO "solid_queue_jobs" ("queue_name", "class_name", "arguments", "priority", "active_job_id", "scheduled_at", "finished_at", "concurrency_key", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING "id"  [["queue_name", "default"], ["class_name", "Turbo::Streams::ActionBroadcastJob"], ["arguments", "{\"job_class\":\"Turbo::Streams::ActionBroadcastJob\",\"job_id\":\"ef62f1e4-04f7-4659-930a-7a3033784eaf\",\"provider_job_id\":null,\"queue_name\":\"default\",\"priority\":null,\"arguments\":[\"10_noticed/notifications\",{\"action\":{\"_aj_serialized\":\"ActiveJob::Serializers::SymbolSerializer\",\"value\":\"replace\"},\"target\":\"notification_bell\",\"targets\":null,\"attributes\":{\"_aj_symbol_keys\":[]},\"partial\":\"notifications/bell\",\"locals\":{\"notification\":{\"_aj_globalid\":\"gid://mortimer/CompletedEmployeeNotifier::Notification/1\"},\"request_id\":\"cc064d04-6187-4e8d-a725-4c56e081b09e\",\"recipient\":{\"_aj_globalid\":\"gid://mortimer/User/10\"},\"_aj_symbol_keys\":[\"notification\",\"request_id\",\"recipient\"]},\"_aj_ruby2_keywords\":[\"action\",\"target\",\"targets\",\"attributes\",\"partial\",\"locals\"]}],\"executions\":0,\"exception_executions\":{},\"locale\":\"da\",\"timezone\":\"Europe/Copenhagen\",\"enqueued_at\":\"2024-08-29T11:30:01.471639000Z\",\"scheduled_at\":\"2024-08-29T11:30:01.471452000Z\"}"], ["priority", 0], ["active_job_id", "ef62f1e4-04f7-4659-930a-7a3033784eaf"], ["scheduled_at", "2024-08-29 11:30:01.471452"], ["finished_at", nil], ["concurrency_key", "[FILTERED]"], ["created_at", "2024-08-29 11:30:01.477197"], ["updated_at", "2024-08-29 11:30:01.477197"]]
13:30:06 web.1  | [ActiveJob] [writer]   ↳ app/models/concerns/noticed/notification_extensions.rb:14:in `broadcast_update_to_bell'
13:30:06 web.1  | [ActiveJob] Failed enqueuing Turbo::Streams::ActionBroadcastJob to SolidQueue(default): SolidQueue::Job::EnqueueError (ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked)
13:30:06 web.1  | [ActiveJob] ↳ app/models/concerns/noticed/notification_extensions.rb:14:in `broadcast_update_to_bell'
13:30:06 web.1  | [writer]   TRANSACTION (0.1ms)  rollback transaction
13:30:06 web.1  | [writer]   ↳ app/controllers/notifications_controller.rb:30:in `mark_read'
13:30:06 web.1  | Completed 500 Internal Server Error in 5084ms (ActiveRecord: 10008.4ms (6 queries, 0 cached) | GC: 4.6ms)
13:30:06 web.1  | 
13:30:06 web.1  | 
13:30:06 web.1  | [writer]   TRANSACTION (0.3ms)  begin transaction
13:30:06 web.1  |   
13:30:06 web.1  | SolidQueue::Job::EnqueueError (ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked)
13:30:06 web.1  | Caused by: ActiveRecord::StatementInvalid (SQLite3::BusyException: database is locked)
13:30:06 web.1  | Caused by: SQLite3::BusyException (database is locked)
13:30:06 web.1  | 
13:30:06 web.1  | Information for: SolidQueue::Job::EnqueueError (ActiveRecord::StatementInvalid: SQLite3::BusyException: database is locked):
13:30:06 web.1  |   
13:30:06 web.1  | 
13:30:06 web.1  | Information for cause: ActiveRecord::StatementInvalid (SQLite3::BusyException: database is locked):
13:30:06 web.1  |   
13:30:06 web.1  | 
13:30:06 web.1  | Information for cause: SQLite3::BusyException (database is locked):
13:30:06 web.1  |   
13:30:06 web.1  | app/models/concerns/noticed/notification_extensions.rb:14:in `broadcast_update_to_bell'
13:30:06 web.1  | app/models/concerns/noticed/notification_extensions.rb:8:in `broadcast_changes'
13:30:06 web.1  | app/controllers/notifications_controller.rb:30:in `mark_read'
13:30:06 web.1  | app/controllers/notifications_controller.rb:3:in `show'
13:30:06 web.1  | app/controllers/concerns/timezone_locale.rb:31:in `switch_locale'

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 23 (12 by maintainers)

Most upvoted comments

Of course! @wdiechmann, you’d need to set retries: 100 in your database.yml configuration, and remove any timeout settings, if you have them.

If that alone doesn’t fix it, you can add this initializer to config/initializers/sqlite3.rb:

module SQLite3Configuration
  private
    def configure_connection
      super

      if @config[:retries]
        retries = self.class.type_cast_config_to_integer(@config[:retries])
        raw_connection.busy_handler do |count|
          (count <= retries).tap { |result| sleep count * 0.001 if result }
        end
      end
    end
end

ActiveSupport.on_load :active_record do
  ActiveRecord::ConnectionAdapters::SQLite3Adapter.prepend SQLite3Configuration
end

My colleague @brunoprietog just pointed me to this PR in Rails: https://github.com/rails/rails/pull/51958 that was merged 3 weeks ago. Looks like this might solve this problem without the need for that patch!

Going to close this one now, thanks again everyone for the patience and excellent troubleshooting 🙏

Thank you for the awesome support!

Thanks a lot! It seems to be just the normal polling starting for both the dispatcher and the worker 🤔 I was going to suggest setting a timeout for SQLite so that it’s passed by Rails to be used as busy_timeout but you are already doing that, setting 5 seconds, and also setting the IMMEDIATE default transaction mode:

default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000
  default_transaction_mode: IMMEDIATE

But I just learnt about https://github.com/sparklemotion/sqlite3-ruby/issues/261, and it seems that in a multi-thread context and MRI, busy_timeout doesn’t quite work and busy_handler should be used instead, which Rails allows as of https://github.com/rails/rails/pull/49352, via retries. I’m not quite sure of what value could make sense… Looking into how many retries would fit in 5 seconds in the way these are performed, I’d say to try with 55 for example:

default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  retries: 55
  default_transaction_mode: IMMEDIATE

You need to remove the timeout option for this to take effect.

Another option, depending on your jobs and load, might be to use less aggressive intervals for Solid Queue polling. The default for workers is 0.1 seconds. You could try with 1 second, and also increase the dispatcher polling to 5 seconds.

  workers:
    - polling_interval: 1
  dispatchers:
    - polling_interval: 5