From 96c134a4e85bbca79ad3bb3186be41d4ba2159de Mon Sep 17 00:00:00 2001 From: Stephen von Takach Date: Tue, 5 Sep 2023 22:30:47 +1000 Subject: [PATCH] fix(base): uploads clean up when request completes instead of using finalize as it's causing `GC Warning: Finalization cycle involving 0x7fa0724dee40` errors --- shard.yml | 2 +- src/action-controller/base.cr | 21 +++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/shard.yml b/shard.yml index 9f7d025..5e4fa7c 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: action-controller -version: 7.2.1 +version: 7.2.2 crystal: ">= 1.9.0" dependencies: diff --git a/src/action-controller/base.cr b/src/action-controller/base.cr index 9349088..53fc4df 100644 --- a/src/action-controller/base.cr +++ b/src/action-controller/base.cr @@ -135,18 +135,6 @@ abstract class ActionController::Base @__render_called__ = false end - # clean up any uploaded files - def finalize - uploads = @__files__ - return unless uploads - - uploads.each_value do |files| - files.each do |file_upload| - file_upload.delete - end - end - end - # the [request context](https://crystal-lang.org/api/latest/HTTP/Server/Context.html) def context : HTTP::Server::Context @__context__ @@ -591,6 +579,15 @@ abstract class ActionController::Base end # END force SSL check {% end %} + # clean up any uploaded files + if uploads = instance.try &.@__files__ + uploads.each_value do |files| + files.each do |file_upload| + file_upload.delete + end + end + end + # Always return the context context end