Skip to content

Stop using dbcancel as the nogvl unblock function - #607

Open
emailrhoads wants to merge 1 commit into
rails-sqlserver:masterfrom
emailrhoads:fix/null-nogvl-ubf
Open

Stop using dbcancel as the nogvl unblock function#607
emailrhoads wants to merge 1 commit into
rails-sqlserver:masterfrom
emailrhoads:fix/null-nogvl-ubf

Conversation

@emailrhoads

Copy link
Copy Markdown

Summary

  • rb_thread_call_without_gvl currently uses dbcancel as the unblock function. MRI invokes that UBF whenever the waiting thread has a pending interrupt, including process-directed signals such as SIGCHLD delivered to main after another thread spawns a child.
  • dbcancel then aborts the in-flight batch. Result#each treats FAIL as an empty success, so long queries can return [] even though SQL Server produced rows.
  • This keeps releasing the GVL (NULL, NULL) so other Ruby threads can run, but no longer cancels SQL on those interrupts. Client :timeout is unchanged (dbsetinterrupt).
  • Tradeoff: Timeout.timeout / Thread#kill wait until the batch finishes or :timeout fires.

Test plan

  • New test: another thread reaps child processes during WAITFOR DELAY; the following SELECT 42 must still return a row.
  • Existing timeout tests still pass (:timeout via dbsetinterrupt).
  • CI on this PR.

MRI calls the UBF on any pending interrupt (including SIGCHLD on main),
which aborted in-flight batches and made Result#each return []. Client
:timeout still uses dbsetinterrupt.

Co-authored-by: Cursor <cursoragent@cursor.com>
@emailrhoads
emailrhoads marked this pull request as draft August 19, 2026 15:02
@emailrhoads
emailrhoads marked this pull request as ready for review August 19, 2026 15:17
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