Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ffi/lib/llhttp/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,17 @@ def initialize(delegate, type: :both)

@callbacks = Callbacks.new

# Keep explicit references to the callback procs. JRuby's FFI does not
# retain Ruby references to procs assigned into FFI::Struct callback
# fields, so without these the JVM may collect the procs and reclaim
# their native trampolines while the parser is still in use, after
# which llhttp_execute completes without invoking any callbacks.
@callback_procs = []

(CALLBACKS + CALLBACKS_WITH_DATA).each do |callback|
if delegate.respond_to?(callback)
@callbacks[callback] = method(callback).to_proc
@callback_procs << (callback_proc = method(callback).to_proc)
@callbacks[callback] = callback_proc
end
end

Expand Down
Loading