Skip to content

Handle kv.sqlite database contention/incomplete transactions - #2790

Merged
RebeccaMahany merged 5 commits into
kolide:mainfrom
RebeccaMahany:becca/sqlite-busy
Aug 12, 2026
Merged

Handle kv.sqlite database contention/incomplete transactions#2790
RebeccaMahany merged 5 commits into
kolide:mainfrom
RebeccaMahany:becca/sqlite-busy

Conversation

@RebeccaMahany

Copy link
Copy Markdown
Contributor

A recent update to modernc.org/sqlite makes _busy_timeout available. When _busy_timeout is set, sqlite will wait for the timeout instead of immediately returning a SQLITE_BUSY error. I am hopeful that this will resolve some of the contention-related error logs that we see.

I chose a timeout of 10 seconds based solely on rungroup.InterruptTimeout.

@RebeccaMahany RebeccaMahany added the bug-fixes Bug Fixes label Aug 10, 2026
@RebeccaMahany
RebeccaMahany marked this pull request as ready for review August 10, 2026 21:47
@brhoades

Copy link
Copy Markdown
Contributor

Oh interesting. Are the errors mostly Windows? I could see multiple threads attempting concurrent sqlite opens; that may need a separate fix.

I've seen it on MacOS before too, come to think of it, coming up as EBUSY from the OS.

@brhoades brhoades left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. This is a good add. I didn't realize this was a modern feature?

require.NoError(t, s.Close())
}

func TestGetSet_Simultaneous(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think testing this with N parallel tests against a single database across platforms might be interesting. Unless we're doing that somewhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have anything with a shared test database at the moment!

@RebeccaMahany

Copy link
Copy Markdown
Contributor Author

@brhoades

Are the errors mostly Windows?

Windows is overrepresented in some of these specific error logs because it's the only OS where we use the launcher watchdog, so the only place where we're writing to the watchdog logs store in kv.sqlite. For error writing settings: upserting into startup_settings: database is locked (5) (SQLITE_BUSY), slightly less than half are Windows (looking very briefly at logs just over today).

@brhoades

Copy link
Copy Markdown
Contributor

Got it. I don't know the proportional fleet size, but if it is a file handle contention problem it'd have to be disproportionate to track with my experience. Just a thought, no blockers from me here.

@RebeccaMahany
RebeccaMahany added this pull request to the merge queue Aug 12, 2026
Merged via the queue into kolide:main with commit 052bcf6 Aug 12, 2026
49 of 50 checks passed
@RebeccaMahany
RebeccaMahany deleted the becca/sqlite-busy branch August 12, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fixes Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants