Skip to content

Commit

Permalink
fix(base): uploads clean up when request completes
Browse files Browse the repository at this point in the history
instead of using finalize as it's causing `GC Warning: Finalization cycle involving 0x7fa0724dee40` errors
  • Loading branch information
stakach committed Sep 5, 2023
1 parent 897b968 commit 96c134a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: action-controller
version: 7.2.1
version: 7.2.2
crystal: ">= 1.9.0"

dependencies:
Expand Down
21 changes: 9 additions & 12 deletions src/action-controller/base.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 96c134a

Please sign in to comment.