Skip to content

Instantly share code, notes, and snippets.

View KJTsanaktsidis's full-sized avatar

KJ Tsanaktsidis KJTsanaktsidis

View GitHub Profile
@KJTsanaktsidis
KJTsanaktsidis / gist:21d7ed46251fbd87bfa14cccbe704133
Created June 13, 2022 00:58
Backtrace showing st_table doing ruby_xmalloc
#0 heap_page_add_freeobj (objspace=0xeb9800, page=0x153da2c0, obj=139975204190960) at gc.c:1850
#1 0x00007f4e98cf35ab in gc_sweep_plane (objspace=0xeb9800, heap=0xeb9838, p=139975204190960, bitset=1, ctx=0x7ffe5ff47e20) at gc.c:5293
#2 0x00007f4e98cf39ad in gc_sweep_page (objspace=0xeb9800, size_pool=0xeb9828, heap=0xeb9838, ctx=0x7ffe5ff47e20) at gc.c:5389
#3 0x00007f4e98cf3f89 in gc_sweep_step (objspace=0xeb9800, size_pool=0xeb9828, heap=0xeb9838) at gc.c:5665
#4 0x00007f4e98cf485d in gc_sweep (objspace=0xeb9800) at gc.c:5900
#5 0x00007f4e98cf8c49 in gc_marks_rest (objspace=0xeb9800) at gc.c:8100
#6 0x00007f4e98cf8daf in gc_marks (objspace=0xeb9800, full_mark=0) at gc.c:8151
#7 0x00007f4e98cfae13 in gc_start (objspace=0xeb9800, reason=512) at gc.c:8967
#8 0x00007f4e98cfaa8a in garbage_collect (objspace=0xeb9800, reason=512) at gc.c:8853
#9 0x00007f4e98cfb567 in garbage_collect_with_gvl (objspace=0xeb9800, reason=512) at gc.c:9225
@KJTsanaktsidis
KJTsanaktsidis / gist:7a72d9ededbec2a01b8d550cc0c54d51
Created June 12, 2022 07:40
recursive event hook backtrace
#0 rb_exec_event_hooks (trace_arg=0x7fad3ded3910, hooks=0x11260d0, pop_p=0) at vm_trace.c:370
#1 0x00007fad42b2d4e3 in rb_exec_event_hook_orig (ec=0x1f96900, hooks=0x11260d0, flag=2097152, self=18549560, id=0, called_id=0, klass=0, data=140381822381360, pop_p=0)
at /home/kj/.rbenv/sources/3.0.4/ruby-3.0.4/vm_core.h:1985
#2 0x00007fad42b30203 in gc_event_hook_body (ec=0x1f96900, objspace=0x11257f0, event=2097152, data=140381822381360) at gc.c:2067
#3 0x00007fad42b317f8 in obj_free (objspace=0x11257f0, obj=140381822381360) at gc.c:2778
#4 0x00007fad42b35a65 in gc_page_sweep (objspace=0x11257f0, heap=0x1125818, sweep_page=0x7fad30a72b40) at gc.c:4891
#5 0x00007fad42b360c8 in gc_sweep_step (objspace=0x11257f0, heap=0x1125818) at gc.c:5098
#6 0x00007fad42b3624e in gc_sweep_rest (objspace=0x11257f0) at gc.c:5151
#7 0x00007fad42b3cd3a in gc_rest (objspace=0x11257f0) at gc.c:8336
#8 0x00007fad42b42a5e in objspace_malloc_increase (objspace=0x11257f0, mem=0x7fad35dac7d0, new_size=904, old_size=0, type=MEMO
@KJTsanaktsidis
KJTsanaktsidis / gist:4917a4cea7d45d6cca01264801841f81
Created June 12, 2022 06:12
Crash calling ruby from newobj
/home/kj/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/sinatra-2.2.0/lib/sinatra/base.rb:1112: [BUG] unexpected situation - recordd:1 current:0
ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0029 p:---- s:0165 e:000164 CFUNC :catch
c:0028 p:0006 s:0160 e:000159 METHOD /home/kj/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/sinatra-2.2.0/lib/sinatra/base.rb:1112
c:0027 p:0019 s:0155 e:000154 METHOD /home/kj/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/sinatra-2.2.0/lib/sinatra/base.rb:1135
c:0026 p:0004 s:0150 e:000149 BLOCK /home/kj/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/sinatra-2.2.0/lib/sinatra/base.rb:949
c:0025 p:0003 s:0147 e:000146 BLOCK /home/kj/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/sinatra-2.2.0/lib/sinatra/base.rb:1112 [FINISH]
c:0024 p:---- s:0144 e:000143 CFUNC :catch
@KJTsanaktsidis
KJTsanaktsidis / backtracie crash
Created June 11, 2022 04:10
Backtracie crash
/home/kj/backtracie/spec/unit/backtracie_spec.rb:240: [BUG] Segmentation fault at 0x0000000000000008
ruby 3.0.4p208 (2022-04-12 revision 3fa771dded) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0056 p:---- s:0271 e:000270 CFUNC :backtrace_locations
c:0055 p:0017 s:0266 e:000265 BLOCK /home/kj/backtracie/spec/unit/backtracie_spec.rb:240
c:0054 p:0005 s:0263 e:000262 BLOCK /home/kj/backtracie/spec/unit/backtracie_spec.rb:230 [FINISH]
c:0053 p:0007 s:0259 E:001140 BLOCK /home/kj/backtracie/spec/unit/backtracie_spec.rb:240 [FINISH]
c:0052 p:0006 s:0256 e:000255 BLOCK /home/kj/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:343
c:0051 p:0010 s:0253 e:000249 BLOCK /home/kj/.rbenv/versions/3.0.4/lib/ruby/gems/3.0.0/gems/rspec-core-3.11.0/lib/rspec/core/memoized_helpers.rb:179 [FINISH]
#!/usr/bin/env ruby
require 'open3'
# rubocop:disable Lint/MissingCopEnableDirective
# rubocop:disable Style/GlobalVars
$stdout_lock = Mutex.new
$stdout.sync = true
Thread.abort_on_exception = true
Pointer at 140292879716464:
rd.h:130
rdkafka_partition.c:2924
rdkafka_cgrp.c:2730
rdatomic.h:86
rdkafka_op.c:830
rdkafka_op.c:860
rdkafka_queue.c:510
rdkafka.c:2060
pthread_create.c:474
#!/usr/bin/env ruby
require 'open3'
@allocated_addrs = {}
@allocation_time = {}
@symbol_cache = {}
@app_pid = ARGV[0]
def resolve_symbol(addr)
@KJTsanaktsidis
KJTsanaktsidis / bpfout
Created September 23, 2021 08:25
bpfout
@allocated_addrs[140548392353792]:
0x7fd431f0d4d4
0xb4fc7a
0x8b7845
0x8c273d
0x8bb2b6
0x937f85
0x9426b8
0x93f4d5
0x93f9b9
@KJTsanaktsidis
KJTsanaktsidis / bpftrace
Created September 23, 2021 07:49
bpftrace
usdt:/usr/local/lib/librdkafka.so.1:librdkafka:rd_malloc {
@allocated_addrs[arg0] = ustack();
@allocation_time[arg0] = nsecs;
}
usdt:/usr/local/lib/librdkafka.so.1:librdkafka:rd_free {
delete(@allocated_addrs[arg0]);
delete(@allocation_time[arg0]);
}
@KJTsanaktsidis
KJTsanaktsidis / rd.h
Created September 23, 2021 07:34
rd.h
// include macros from SystemTap project
#include <sys/sdt.h>
// ... lots of librdkafka code ...
static RD_INLINE RD_UNUSED void *rd_malloc(size_t sz) {
void *p = malloc(sz);
rd_assert(p);
// Add a call to DTRACE_PROBE here to call our probe with the address