-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segmentation Fault in AllocAppender #470
Comments
Further testing shows that m_data is itself inaccessible. |
Using VibeManualMemoryManagement, the segfault doesn't occur. |
I had problems with GC mode as well, I think vibe's memory should be manually managed by default. |
I'll close this issue as apparently it is a bad report without a reproducible case. |
I think I just hit this bug - I got a segfault in memcpy and a broken stack trace. Unfortunately the application is closed-source and the crash only happened after ~3 hours. The |
Possible additional instance: http://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/thread/17107/ |
@yazd I don't understand, in the first post you said "The error is reproducible every time"; why was this closed later as a "a bad report without a reproducible case"? In my case, which @s-ludwig mentions, the bug is not reproducible deterministically, so if you have a deterministic example sharing it would help. |
Originally, it was reproducible for me, but it was not a minimal testcase. I changed some stuff and it got working and I lost the case. I'll try going back to that project and to reproduce the issue again. I think it's worth a few hours of my time. |
@luismarques did you have manual memory management when this bug occured? |
Nop, with the manual memory management version everything worked correctly. |
I had tons of problems without manual memory management, that's why I still hold that it should be on by default. |
It's dangerous (i.e. not In other languages this wouldn't be really noteworthy (especially C and partially C++), but for D it's kind of the norm that you can't do much wrong in terms of memory corruption because of the GC, so this is kind of unexpected. |
That's funny because I thought the |
@etcimon: I'm using the default automatic memory management. |
Yes, but the HTTP server uses |
So.. just a quick guess here to practice my vibe skills, but doesn't these use cases mostly refer to ubytes that were received by a TCP Connection? That would be in the circular buffer, and the access violation means the circular buffer got collected by the GC, yes? edit: Nvm that wouldn't be possible because |
…ess tests to GCAllocator. See #470.
I've just had a crash (invalid write access) in that location that was reproducible 100%. After changing the use of |
I wasn't able to reproduce my case, but fortunately, you were. Hopefully this gets it fixed. |
Another piece of empirical evidence: I've just discovered that the vibed.org website frequently crashed due to a general protection fault, but stopped doing so ever since I've rebuilt with the "fixed" vibe.d version. So it's not guaranteed that the GPF was caused by this issue here, but at least it seems likely. |
Closing until new evidence comes up. The vibed.org process didn't crash anymore since the fix has been incorporated (runs for 3 days now). |
So this means |
Ok I found a few huge bugs in the https://github.com/D-Programming-Language/druntime/blob/master/src/gc/gc.d#L674 Apparently the So, if you do the following you should get a write access violation: The 2048 byte allocation will be ignored because ...AND if the old and new allocation sizes are larger than a page (4096 bytes) and consecutive blocks of pages aren't found in the pagetable, it also skips the cache update by going the same malloc route as stated above https://github.com/D-Programming-Language/druntime/blob/master/src/gc/gc.d#L657 This will ALSO prevent pages from being freed, and will lead to the GC memory leaks which I've experienced! (finally found it!)
|
The magic numbers are just there as a safety measure to detect when the postblit constructor or the destructor is called on uninitialized memory. This mainly happens in conjunction with AAs, but also in some other cases (ternary operator, I think), but is not really relevant for GC allocations. But the situation is far better now than a year ago, where it still frequently triggered. |
Regarding the GC realloc issue, it sounds like that could also be the normal behavior, where an additional and completely separate block of memory is allocated. Because there might still be references to the old one, it would be kept instead of being freed. But it would still be collected during the next collection run, when there are in fact no references left. Disclaimer: I didn't look closer at the source code, yet, so this is pure speculation. |
For this it would have to keep the old pointer around, but this branch of the code essentially does what extend does but skipping the size cache. I'm pretty sure it's a bug, you could add
here: https://github.com/D-Programming-Language/druntime/blob/master/src/gc/gc.d#L706 And I'm pretty sure it would fix this issue #470 without resorting to extend, and it would also fix tons of other issues |
But that would update the size of the old block, which doesn't change in size. Only a new block is allocated there, AFAICS. |
Yes you're right, the key changes so it doesn't need to be updated, so it's something else.. |
Though this does seem like the right reason the problem would be caused, just not in this specific execution path. It could be when the |
Seems like the |
This execution path seems to return the wrong cache size:
|
That looks like it may indeed be a bug. Unfortunately it doesn't explain the vibe.d issue, because no explicit free calls are used there and the normal collection run resets the cache. |
Free was probably a bad example, the internal use of |
Hm, but |
Here's how it could have affected vibe.d :
|
Yes that's true. I'm not sure anymore if that's the buggy path I'll keep on researching it more.. |
https://github.com/D-Programming-Language/druntime/blob/master/src/gc/gc.d#L588 This could be a good candidate |
After giving it long thoughts, I think an |
Got this segmentation fault when rendering a diet template.
The error is reproducible every time.
While trying to debug it, I logged the variables in AllocAppender put(). And although m_remaining reported enough space, accessing it produced the segfault.
The text was updated successfully, but these errors were encountered: