Repository navigation
Closed
Description
Noticing the below crash in prod on our first attempt to test 9.0
(gdb) bt
#0 0x00002aaec7fe24ad in vfprintf () from /lib64/libc.so.6
#1 0x00002aaec7fed287 in fprintf () from /lib64/libc.so.6
#2 0x00002aaec569011d in fatal_va(const char *, const char *, typedef __va_list_tag __va_list_tag *) (hdr=hdr@entry=0x2aaec570dafd "Fatal: ", fmt=fmt@entry=0x2aaec570d2a7 "%s:%d: failed assertion `%s`", ap=ap@entry=0x2aaed9104858) at ink_error.cc:47
#3 0x00002aaec5690356 in ink_abort (message_format=message_format@entry=0x2aaec570d2a7 "%s:%d: failed assertion `%s`") at ink_error.cc:96
#4 0x00002aaec568d045 in _ink_assert (expression=expression@entry=0x8210bd "current_block != nullptr", file=file@entry=0x820e40 "SSLNetVConnection.cc", line=line@entry=271) at ink_assert.cc:37
#5 0x0000000000742dc3 in ssl_read_from_net (ret=<synthetic pointer>, lthread=<optimized out>, sslvc=0x2aaf5f602340) at SSLNetVConnection.cc:271
#6 SSLNetVConnection::net_read_io (this=0x2aaf5f602340, nh=0x2aaecd809d80, lthread=<optimized out>) at SSLNetVConnection.cc:662
#7 0x0000000000761b48 in NetHandler::process_ready_list (this=this@entry=0x2aaecd809d80) at UnixNet.cc:412
#8 0x0000000000761e3d in NetHandler::waitForActivity (this=0x2aaecd809d80, timeout=<optimized out>) at UnixNet.cc:547
#9 0x00000000007c02fa in EThread::execute_regular (this=this@entry=0x2aaecd806000) at UnixEThread.cc:266
#10 0x00000000007c05c2 in EThread::execute (this=0x2aaecd806000) at UnixEThread.cc:327
#11 0x00000000007be969 in spawn_thread_internal (a=0x2aaec9565180) at Thread.cc:92
#12 0x00002aaec72e6dd5 in start_thread () from /lib64/libpthread.so.0
#13 0x00002aaec8097ead in clone () from /lib64/libc.so.6
(gdb)
(gdb) p (*(IOBufferBlock *) 0x2aaf619e0880).next.m_ptr
$15 = (IOBufferBlock *) 0x2aaf2a5ad480
(gdb) p (*(*(IOBufferBlock *) 0x2aaf619e0880).next.m_ptr)
$12 = {
<RefCountObj> = {
<ForceVFPTToTop> = {
_vptr.ForceVFPTToTop = 0x7c5b68 <vtable for IOBufferBlock+16>
},
members of RefCountObj:
m_refcount = 1
},
members of IOBufferBlock:
_start = 0x0,
_end = 0x0,
_buf_end = 0x3532254332353215 <Address 0x3532254332353215 out of bounds>,
_location = 0x7e0a20 "memory/IOBuffer/HttpSM.cc:5840",
data = {
m_ptr = 0x2aaed5736d80
},
next = {
m_ptr = 0x0
}
}
(gdb) p (*(*(IOBufferBlock *) 0x2aaf619e0880).next.m_ptr)._start
$17 = 0x0
(gdb) p (*(*(IOBufferBlock *) 0x2aaf619e0880).next.m_ptr)._buf_end
$18 = 0x3532254332353215 <Address 0x3532254332353215 out of bounds>
(gdb) p (*(*(IOBufferBlock *) 0x2aaf619e0880).next.m_ptr)._end
$13 = 0x0
(gdb)
(gdb) p (*(*(IOBufferBlock *) 0x2aaf619e0880).next.m_ptr).next.m_ptr
$11 = (IOBufferBlock *) 0x0
(gdb)
(gdb) p *(*(IOBufferBlock *) 0x2aaf619e0880).next.m_ptr.data.m_ptr
$4 = {
<RefCountObj> = {
<ForceVFPTToTop> = {
_vptr.ForceVFPTToTop = 0x7c5b40 <vtable for IOBufferData+16>
},
members of RefCountObj:
m_refcount = 1
},
members of IOBufferData:
_size_index = 3833167203381096996,
_mem_type = DEFAULT_ALLOC,
_data = 0x0,
_location = 0x7e0a20 "memory/IOBuffer/HttpSM.cc:5840"
}
(gdb) p *(*(IOBufferBlock *) 0x2aaf619e0880).data.m_ptr
$5 = {
<RefCountObj> = {
<ForceVFPTToTop> = {
_vptr.ForceVFPTToTop = 0x7c5b40 <vtable for IOBufferData+16>
},
members of RefCountObj:
m_refcount = 2
},
members of IOBufferData:
_size_index = 5,
_mem_type = DEFAULT_ALLOC,
_data = 0x2aaf60059000 "fZEERBbg3lcGkSgSxwSEiO8Ho; sl=\"v=1&sGsuF\"; lidc=\"b=OB50:s=O:r=O:g=2299:u=15:i=1591116679:t=1591203079:v=1:sig=AQE4cHsiP5eLt8aPshPpFX0rbvF3arjp\"\r\nHost: www.linkedin.com\r\nUser-Agent: Mozilla/5.0 (iPhone"...,
_location = 0x81cc70 "memory/IOBuffer/ProtocolProbeSessionAccept.cc:59"
}
Activity
sudheerv commentedon Jun 3, 2020
It looks like the root of the problem is that
IOBufferData::_size_indexseems garbage (3833167203381096996). This typically comes down via the call tonew_MIOBufferbut, reviewing the code foralloc_indexpassed withnew_MIOBuffer, couldn't find a smoking gun yet where this could be garbage.Specifically, the line number (location) from the corrupted IOBufferData shows HttpSM.cc:5840 and the logic in that code block that sets alloc_index didn't seem to have any issues.
[-]Crash in ssl_read_from_net due to assert failure for null buffer block[/-][+]ssl_read_from_net assert failure for null buffer block[/+]sudheerv commentedon Jun 4, 2020
This may be due to a similar root cause as
#6850
I'm wondering if we should bump up the default value of
proxy.config.io.max_buffer_sizefrom 32K to higher - probably 1M (index = 13) or 2M even (index=14)?sudheerv commentedon Jun 6, 2020
@zwoop Added more instrumentation to figure out where the
_size_indexmay be turning into garbage and it seems to be caused bymax_iobuf_sizebeing garbage somehow (it's supposed to be set based onproxy.config.io.max_buffer_sizeduringink_event_system_init(), but, not sure if there's some sort of initialization ordering issue or something else, but, when the caller relies on that default max instead of explicitly passing it in (like you pointed), sometimes, this garbage value is messing up the returned allocSize and that results in corrupting the IOBuffer index and from there it's all downhill. Regardless, the strategy you recommended to make sure callers explicitly pass it in and replace the config based value into a #define sounds perfect to address this.masaori335 commentedon Jun 7, 2020
Nice catch!
Does this mean bad error handing of callingbuffer_size_to_index()in this case?I don't object bumping the default value or removing it, but even if we bump the default value or explicitly set the
max, thesizecould be larger than it and the function returns an error.Update: It seems a factor of this is
buffer_size_to_index()returns invalid index even if givenmaxis out of range (0 - 14). I wonder thatbuffer_size_to_index()should returnDEFAULT_BUFFER_SIZESor-1as error.masaori335 commentedon Jun 8, 2020
Could you add an assert to make sure the
max_iobuf_sizeis in bewteen 0 and MAX_BUFFER_SIZE_INDEX (14) at the startup?sudheerv commentedon Jun 9, 2020
Yeah, I double checked but
max_iobuffer_sizedoesn't seem to get corrupted during start up. It seems to get corrupted sometime during the run as otherwise, it'd crash much more frequently or even all the time. After a few fixes and most likely reverting PR 4028 seems to have solved this.Additionally, #6869 forces the caller to always pass a max iobuf size and not rely on the global default at all. Allowing the callers to pass the max explicitly allows more flexibility in customizing the max for different use cases (for e.g some users may set high HostDB buffer size while some may set high POST buffer size).
sudheerv commentedon Jun 20, 2020
Ran ASAN in prod (couldn't run it for longer than an hour before maxing out CPU) and our staging/integration environment (over a day, slow burn as the qps is lower) and found a few heap corruption (in our internal plugins and libraries) and heap overflow issues (#6916 ).
After fixing those, the occurrence of this crash dropped significantly (from once every 3-4 hours to 1-2/day).
Will open a separate issue for the findings on the last remaining crashes.
sudheerv commentedon Jun 25, 2020
@masaori335 Just fyi, It looks like the root cause of the corruption of globals is #6950 - finally was able to run ASAN that could catch this.
masaori335 commentedon Sep 13, 2020
I got exactly same crash on my 9.0.x branch (052b535 + my changes) under super heavy load by performance test.
The symptom looks same, the
size_indexof MIOBuffer is garbage (140524527145360).@sudheerv the 9.0.x branch has all fixes related this?
masaori335 commentedon Sep 15, 2020
NVM, ASan detected heap-buffer-overflow. It's the root cause.