Skip to content

fix(routing): Release the GVL during native model setup - #5

Merged
erickreutz merged 1 commit into
masterfrom
eric/release-gvl-for-planner-setup
Aug 23, 2026
Merged

fix(routing): Release the GVL during native model setup#5
erickreutz merged 1 commit into
masterfrom
eric/release-gvl-for-planner-setup

Conversation

@erickreutz

Copy link
Copy Markdown
Member

Planner model close and warm-route restoration can spend tens of seconds in native OR-Tools code. Those calls held MRI's GVL, so one slow planner job prevented unrelated Ruby threads in the same process from serving requests, heartbeating, or handling signals. This addresses the process stalls investigated in the initial report and the second occurrence.

RoutingModel#close_model and #read_assignment_from_routes now release the GVL when the model uses only native callbacks. Models with Ruby transit callbacks retain the GVL so callback execution remains safe. Route arrays are converted to owned C++ values before release, and returned assignments are wrapped only after Ruby execution resumes.

The callback-aware Ruby wrappers are the safety boundary. Raw native callback, solve, close, and assignment-restoration entry points are private so callers cannot bypass that gate. The planner algorithm and routing results remain unchanged; an individual native call can still run for a long time, but it no longer pauses the entire Ruby process.

Allow Ruby threads to keep running while callback-free routing models close and restore route assignments. Keep the GVL when Ruby transit callbacks may execute.
@erickreutz
erickreutz merged commit 472c250 into master Aug 23, 2026
6 checks passed
@erickreutz
erickreutz deleted the eric/release-gvl-for-planner-setup branch August 23, 2026 21:07
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