Skip to content

Long running queries cause freezing when using sqlite #28933

Open
@PeterSurda

Description

@PeterSurda

Description

When using the sqlite backend, a long running query will freeze both the web UI as well as the ssh server. During the freeze, there is nothing in the log, and one CPU core is pegged at 100%. After moving to MariaDB, the query (see below) will still take a very long time, and mariadbd will still fully utilise one core or more, but due to more fine grained locking there is no freezing anymore.

The freezing happened during startup (about 2 hours), and when the "Cron: Check all repository statistics" job was running (between 10 minutes and 2 hours). I was only able to obtain the problematic query (for the cron job) after moving to MariaDB. I don't know if in both cases it's the same query:

SELECT `label`.id FROM `label` WHERE `label`.num_closed_issues!=(SELECT COUNT(*) FROM `issue_label`,`issue` WHERE `issue_label`.label_id=`label`.id AND `issue_label`.issue_id=`issue`.id AND `issue`.is_closed=?)

My attempts to debug didn't provide much helpful results, as I said during the freeze the UI is unresponsive and I can't git pull (throws an error after 1 minute). The logs don't change, the files on the filesystem don't change other than the session files. There is negligible disk I/O. My server is way overpowered for my gitea installation, with 24 cores and more RAM than the whole gitea data volume, and a SSD RAID. I tried a strace, and all I could see was threads waiting for futexes. I was running a slightly older version of gitea, and I tried fixing it by upgrading to the latest docker image, but it only got worse (query took longer to run). Only the educated guess this could be a long running query combined with sqlite finally helped me.

The way I see it, there are two issues:

  • there is a long running query which perhaps could be optimised
  • if there is a long running query and you're using sqlite, gitea interaction freezes

It's not really a problem for me anymore since after moving to MariaDB there is no observable freeze anymore, but perhaps someone else will experience this, so it would be helpful to have some sort of detection or mitigation of this.

Gitea Version

1.21.4

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

gitea internal

Operating System

Ubuntu 22.04

How are you running Gitea?

docker compose, official image

Database

SQLite

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions