Repository navigation
Commit 057f362
committed
Retain llhttp callback procs to fix intermittent JRuby hang
On JRuby, the full test suite would intermittently hang forever in
Connection#read_more waiting for response data that had already been
received and consumed from the socket.
llhttp-ffi assigns per-parser callback procs into an FFI::Struct
(LLHttp::Callbacks) and keeps no other reference to them. JRuby's FFI,
unlike MRI's, does not retain Ruby references to procs assigned into
struct callback fields, so the procs become garbage as soon as
LLHttp::Parser#initialize returns. Once the JVM garbage-collects them,
the native callback trampolines are reclaimed and llhttp_execute
completes successfully without invoking any callbacks. The parser then
reports no progress, so read_headers! loops back into a blocking
readpartial that never returns.
Prepend a module to LLHttp::Callbacks that retains each assigned proc
on the struct instance, tying the trampolines' lifetime to the parser
that owns them. A minimal repro (LLHttp::Parser + java.lang.System.gc)
fails on the first iteration without this fix and survives thousands of
iterations with it; the full suite passed repeated JRuby runs.
This should ultimately be fixed upstream in llhttp-ffi.1 parent a65a8d2 commit 057f362
2 files changed
Lines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
10 | 19 | | |
11 | 20 | | |
12 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
5 | 22 | | |
6 | 23 | | |
7 | 24 | | |
| |||
0 commit comments