summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <[email protected]>2025-06-11 13:59:38 -0400
committerPeter Zhu <[email protected]>2025-06-12 10:02:44 -0400
commitd55c463d563800311d6dab23edeec16abd45068d (patch)
tree096c816a62fe10435d35fa938b780bcad116325a
parenta74c38520844252b0308c434173058efbdb06054 (diff)
Fix memory leak of Ractor basket when sending to closed Ractor
The following script leaks memory: r = Ractor.new { } r.value 10.times do 100_000.times do r.send(123) rescue Ractor::ClosedError end puts `ps -o rss= -p #{$$}` end Before: 18508 25420 32460 40012 47308 54092 61132 68300 75724 83020 After: 11432 11432 11432 11432 11432 11432 11432 11432 11432 11688
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13590
-rw-r--r--ractor_sync.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/ractor_sync.c b/ractor_sync.c
index 0fcc293504..204c800a06 100644
--- a/ractor_sync.c
+++ b/ractor_sync.c
@@ -1197,6 +1197,7 @@ ractor_send_basket(rb_execution_context_t *ec, const struct ractor_port *rp, str
RUBY_DEBUG_LOG("closed:%u@r%u", (unsigned int)ractor_port_id(rp), rb_ractor_id(rp->r));
if (raise_on_error) {
+ ractor_basket_free(b);
rb_raise(rb_eRactorClosedError, "The port was already closed");
}
}