Skip to content

Add interrupt handle #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add interrupt handle #493

wants to merge 1 commit into from

Conversation

jankramer
Copy link

@jankramer jankramer commented Apr 11, 2025

This PR adds an InterruptHandle that allows interrupting long-running queries from another thread. Internally, this calls the duckdb_interrupt function from the C API. The implementation is inspired by rusqlite.

It seems to get the job done, but a couple of thoughts:

  1. Testing the interrupts is a bit tricky. I wasn't able to come up with a deterministic approach, so I took inspiration from tests in other client API: simply kick off an expensive query and interrupt it.
  2. Unfortunately, the error code returned on interrupt is ErrorCode::Unknown, so we have to resort to a match on the error message. Works for now, but I'm wondering if there is a way to do this in a cleaner way, or if the actual error code is simply not exposed from the underlying API.
  3. I'm not very familiar with the safety aspects of interfacing with the C API, so a critical pair of eyes is welcome.

Previous attempt at adding this feature: #343.

@jankramer jankramer marked this pull request as ready for review April 11, 2025 20:55
Exposes the `duckdb_interrupt` function from the C API to allow
consumers to interrupt long-running queries from another thread.

Inspired by rusqlite: https://docs.rs/rusqlite/latest/rusqlite/struct.InterruptHandle.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant