Artifacts Associated With Ticket db4f2843cd
Ticket change [a8df52dc26] (rid 220805) by sebres on 2023-12-05 22:21:04:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-markdown"
- comment initialized to:
I saw this segfault very sporadic previously (as an after-effect of a buffer overrun somewhere by IO operations with objects), just it was like a heisenbug and I never caught it. Unless I implemented some module using `Tcl_ReadChars` with `appendFlag = 1`, and with that command I could reproduce this BO relative simply. Since the segfault is almost always a result of buffer overrun, I'll not provide the callstack here (which is mostly caused by corrupt object and thus broken objects heap in thread-alloc). I already fixed it on my side, so will backport it to new 8.6-based branch now.
- foundin initialized to: "any"
- is_private initialized to: "0"
- login: "sebres"
- priority initialized to: "5 Medium"
- private_contact initialized to: "50e9528765c18296566374b3fde2df942c394efd"
- resolution initialized to: "None"
- severity initialized to: "Critical"
- status initialized to: "Open"
- submitter initialized to: "sebres"
- subsystem initialized to: "10. Objects"
- title initialized to: "Sporadic segfault (BO) using tclIO"
- type initialized to: "Bug"
Ticket change [05ba2431ea] (rid 220811) by sebres on 2023-12-05 23:11:11:
- icomment:
Fixed in [cc90065303e11f36].<br/> The reason for this tricky bug is that [/file?ci=cc90065303e11f36&name=generic/tclStringObj.c&ln=1279-1283|Tcl_AppendToObj] always prefers unicode representation to utf-8 if object has unicode (in opposite to [/file?ci=cc90065303e11f36&name=generic/tclStringObj.c&ln=959|Tcl_SetObjLength] which always prefer utf-8 if it is there), and so <code>Tcl_AppendToObj</code> would rather enlarge the unicode representation of object (basically reserve place for unicode data) if it shimmers to real unicode somewhere by processing outside, however the <code>ReadChars</code> (that itself always works with utf-8 due to external to utf-8 conversions by encoding etc) expects that the buffer of utf-8 gets enlarged instead, what doesn't happen by backwards utf-8 regeneration in followed [/artifact?name=8e47d1977522188d&ln=6119-6122|TclGetString].<br/> It would only work with <code>Tcl_AppendToObj</code> if we working on completely new or empty object (e. g. <code>appendFlag = 0</code> which would clear it and so tries to reuse the buffer) or it got duplicated (if shared) previously, and duplication prefers utf-8 representation, etc.<br/> It was really rare, because really tricky, since it expects certain constellation (like <code>appendFlag = 1</code> and "shimmering" to real unicode) to get reproduced. Anyway fixed now, waiting for CI.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Pending"
- icomment:
Ticket change [df57d0da6a] (rid 220830) by jan.nijtmans on 2023-12-06 13:39:58:
- icomment: "Looks good to me. Many thanks!"
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
Ticket change [257d3e53e7] (rid 220834) by sebres on 2023-12-06 17:27:51:
- closedate changed to: "2460285.2276809"
- closer changed to: "sebres"
- icomment: "Thus merged to 8.6 in [c5a68de09a4b3fc4]"
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- status changed to: "Closed"
Ticket change [a2c651f53e] (rid 221602) by oehhar on 2024-01-22 15:10:12:
- closedate changed to: "2460332.13208447"
- closer changed to: "oehhar"
- icomment:
This fix has a big performance impact on large files, see [da16d15574]. *Tcl_SetObjLength* does not allocate in advance like *Tcl_AppendToObj* and thus makes one realloc per 4096 bytes read. The issue fixed in this ticket may only be triggered, if an extension calls *Tcl_ReadChars* with an object having a string representation in unicode. This never happens in the core. Thus, the fix is reverted for now by commit [7a188dd1c9]. Nevertheless, the issue persists for users of the C interface.
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
Ticket change [2fddea253a] (rid 221604) by sebres on 2024-01-22 15:13:08:
- closer changed to: "nobody"
- icomment:
The fix [cc90065303e11f36] is reverted in [7a188dd1c9b28f99] because of performance regression (due to slower buffer growth resulting to too many realocks).
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Rejected"
- status changed to: "Open"
Ticket change [80d71228eb] (rid 221610) by jan.nijtmans on 2024-01-22 22:34:37:
- icomment:
Would [100933523c937604|this] help? Explanation: If we know that Tcl_AppendToObj() doesn't behave well with tclStringType, and we know also that it has a string representation (because Tcl_GetStringFromObj() is called just before), we can simply remove the IntRep, can we? Just an idea ....., quite harmless. @sebres, would this help in your situation?
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [63694313f7] (rid 221611) by sebres on 2024-01-23 00:35:43:
- icomment:
No, it wouldn't help. Moreover it'd completely regress (would probably have still worse performance than my initial fix) because would "remove" previously enlarged buffer on every iteration. Even if the object is utf-8 append makes a string, that doesn't have unicode, but contains info in stringPtr about the bytes buffer. The removal of internal representation would simply cause that info like stringPtr->allocated get lost. Basically, the simplest fix could be to declare AppendUtfToUtfRep as internal TclAppendUtfToUtfRep and call it instead of Tcl_AppendToObj.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [4cb2b64fee] (rid 221612) by kevin_walzer on 2024-01-23 03:04:02:
- icomment:
This discussion has been very helpful because it helped me track down a crashing bug in tcltls. Thank you!
- login: "kevin_walzer"
- mimetype: "text/plain"
- icomment:
Ticket change [aace438626] (rid 221619) by oehhar on 2024-01-23 08:41:15:
- icomment:
Great Kevin. So, this is a real issue confirmed by two Wizards. Could you imagine a test case? I suppose, we need a piece of C-code which crafts the object passed to Tcl_ReadChars in a certain way. Take care, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
- icomment:
Ticket change [a1cd37584f] (rid 221725) by sebres on 2024-01-26 22:48:43:
- icomment:
I added performance regressions tests for <code>read</code> in [492aaec52129ccbc], that illustrates pretty well the quadratic regression in absence of append (doubling of bytes in internal object used for read on every iteration). The result of execution (original 8.6 vs. previous fix without append) can be found as diff in [https://gist.github.com/sebres/0875a4a75c489b13b6cba8fc9adcc99a|gist.github.com/sebres/0875a4a75c489b13b6cba8fc9adcc99a]. As one indeed can see the regression is pretty obvious (because of too many reallocs), but...<br/> It looks strange if one try to use larger buffersize: 1. the regression is still quadratic even if large buffer size is used (1MB instead of 4KB), however it becomes a bit faster with larger buffersize. 2. still worse is that even by original version with append, the usage of large buffersize degrades (whether I'd expect vice versa result), for example reading 10M blocks it takes 37ms/# by 4KB vs. 104ms/# by 1MB. So it looks like command <code>read</code> or rather <code>Tcl_ReadChars</code> internally use small chunks (a bit unexpected for my taste) or it has another issue yet (not directly related to the "append" or "realloc" predicament).
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [94ed54b952] (rid 221896) by sebres on 2024-01-29 11:12:17:
- icomment:
Found the discrepancy by 4K vs. 1M buffer size - it was interim flush on output side (fixed in [2dce470bdfdd9f25]) - now it works as expected: there is almost no bottleneck with large buffer anymore. <br/>Also updated [https://gist.github.com/sebres/0875a4a75c489b13b6cba8fc9adcc99a|gist] with new result of performance test.
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [251096d395] (rid 221903) by sebres on 2024-01-29 14:05:10:
- icomment:
BO ultimately fixed in [37e659d589622e28], and also like before function <code>ReadChars</code> follows TCL STRING GROWTH ALGORITHM. <br/>As expected the tests chan.perf.tcl doesn't show any regression too (it's even faster now).<br/>
- login: "sebres"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Pending"
- icomment:
Ticket change [3bc9458bf3] (rid 221906) by sebres on 2024-01-29 14:12:01:
- closedate changed to: "2460339.09168104"
- closer changed to: "sebres"
- login: "sebres"
- mimetype: "text/plain"
- status changed to: "Closed"
Ticket change [0dec9f7358] (rid 221907) by oehhar on 2024-01-29 14:21:06:
- closedate changed to: "2460339.09799375"
- closer changed to: "oehhar"
- icomment:
Looks like a clean solution with all pitfall corner cases fixed. Will you merge to core-8-branch and main branches ? Thank you and take care, Harald
- login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"
Ticket change [3d7ee117b3] (rid 221908) by sebres on 2024-01-29 14:40:15:
- closedate changed to: "2460339.11129457"
- closer changed to: "sebres"
- icomment:
Well, I wanted wait for a CI firstly (since at some point only few branches are covered in CI, other branches would not trigger GHA at all)... If all tests passed, I'd merge it.
- login: "sebres"
- mimetype: "text/plain"
Ticket change [1ee70036d4] (rid 221909) by oehhar on 2024-01-29 14:52:56:
- closedate changed to: "2460339.12009329"
- closer changed to: "oehhar"
- icomment:
Great. Please consider, that others may be in troubble, as they can not merge other stuff without mergin your change. Or they have to back it out. If you want to run a CI test, I think, there are possibilities to test a branch, while modifying a certain CI instruction file. Thank you ! Harald
- login: "oehhar"
- mimetype: "text/plain"
Ticket change [59e203e6aa] (rid 221921) by sebres on 2024-01-29 15:43:56:
- closedate changed to: "2460339.15551019"
- closer changed to: "sebres"
- icomment:
> <i>they can not merge other stuff without mergin your change.</i> One doesn't necessarily need to merge 8.6 to 8/main right now (can be made later). > <i>Or they have to back it out.</i> Why should they? If needed to merge 8.6 to 8/main, then it can surely be done with my change. The changes are simple and obvious, and even if it'd conflict somewhere, they can be solved very simply (somehow it belongs to the work with distributed SCM repos, so everyone should be able to do that). But OK, it is done now. > <i>If you want to run a CI test, I think, there are possibilities to test a branch, while modifying a certain CI instruction file.</i> Too inconvenient... Also guess must do that twice (depends on main flow config) and in worse case wait for fossil to git two times. And after all revert config backwards. Previously I had my own fossil2git, so could test in GHA on forked repo, but they are too far apart now.
- login: "sebres"
- mimetype: "text/x-markdown"
Ticket change [b01e3dbbd8] (rid 221922) by oehhar on 2024-01-29 16:14:51:
- closedate changed to: "2460339.1769899"
- closer changed to: "oehhar"
- icomment:
THank you for your comprehension, I appreciate ! Harald
- login: "oehhar"
- mimetype: "text/plain"
Ticket change [2bdc663954] (rid 231220) by pooryorick on 2024-08-25 08:23:18:
- closedate changed to: "2460547.84952346"
- closer changed to: "pooryorick"
- icomment:
sebres: Could you refrain from using non-standard acronyms like "BO" in your communications, and particularly in tickets? You use them frequently enough that they become a barrier to readability.
- login: "pooryorick"
- mimetype: "text/x-fossil-wiki"
Ticket change [8e6759e097] (rid 231221) by jan.nijtmans on 2024-08-25 10:58:12:
- closedate changed to: "2460547.9570935"
- closer changed to: "jan.nijtmans"
- icomment:
@Nahan, don't BO (Blame Others), not even BO (Barack Obama) if you don't know what BO (buffer overflow) means
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
Ticket change [a4eb53a04d] (rid 232000) by pooryorick on 2024-08-28 13:42:40:
- closedate changed to: "2460551.07130025"
- closer changed to: "pooryorick"
- icomment:
Here are some others to noodle on: CP ([8f89e2e059aafa1c]), ,ISC ([fa6bf38d0728fbc7]), JD [16e4fc30961de5dc], NTS ([8c4082563d6a7ebd]), RC ([f583715154c6f33d]), SF ([f583715154c6f33d]), SO ([fec0c17d39db02fa]). Of course it's possible to figure all these out, but it takes time and impacts readability, and even for the ones we all know it takes time to verify that it means what we think it means in that context. BO approves of this message.
- login: "pooryorick"
- mimetype: "text/x-fossil-wiki"