Skip to content
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 some rare cases #28

Closed
tornillo opened this issue Nov 8, 2015 · 12 comments · Fixed by #29 or #31
Closed

Segmentation fault in some rare cases #28

tornillo opened this issue Nov 8, 2015 · 12 comments · Fixed by #29 or #31

Comments

@tornillo
Copy link

tornillo commented Nov 8, 2015

Hi!

I have a project with a complex structure of xsl and xml data.
Production environment is not highload (less than 10 rps).
Segfault occurs for every 300-1000 request, but 100% when I try to run synthetic performance tests.

To reproduce this error, i've created a isolated example, in which the error occurs on different versions of Node (0.12, 4, 5), but more often on 4-5.
(libxslt is compiled from master to work with Node 4-5)

require('segfault-handler').registerHandler('crash.log');

var libxslt = require('libxslt');

var xml = '<?xml version="1.0" encoding="utf-8"?>\n<root></root>';
var xsl = '<?xml version="1.0" encoding="utf-8"?>\n' +
    '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">' +
    '<xsl:template match="/"><xsl:apply-templates /></xsl:template>' +
    '</xsl:stylesheet>'
;

libxslt.parse(xsl, function (err, xslObject) {
    var transform = function () {
        xslObject.apply(xml, function (err, result) {});
    };

    var counter = 10e3;

    while (counter--) {
        transform();
    }
});

Error logs are different from run to run.

Log1:

*** Error in `node': double free or corruption (!prev): 0x000000000265e8f0 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x7d1fd)[0x7f58ae9071fd]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(xsltApplyTemplates+0x697)[0x7f58ac08ec47]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x11d26)[0x7f58ac089d26]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x15662)[0x7f58ac08d662]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(xsltProcessOneNode+0x78)[0x7f58ac08dd38]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x1973b)[0x7f58ac09173b]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(_ZN11ApplyWorker7ExecuteEv+0x43)[0x7f58ac088303]
node[0xfd11a1]
node[0xfdf449]
/lib64/libpthread.so.0(+0x7df5)[0x7f58aec52df5]
/lib64/libc.so.6(clone+0x6d)[0x7f58ae9801ad]
======= Memory map: ========
00400000-01706000 r-xp 00000000 fd:01 2341768                            /home/t/.nvm/versions/node/v5.0.0/bin/node
01905000-0191f000 rw-p 01305000 fd:01 2341768                            /home/t/.nvm/versions/node/v5.0.0/bin/node
0191f000-01930000 rw-p 00000000 00:00 0
01f38000-026d5000 rw-p 00000000 00:00 0                                  [heap]
408b5123000-408b5124000 r-xp 00000000 00:00 0
64dd4049000-64dd4200000 ---p 00000000 00:00 0
64dd4200000-64dd4205000 rw-p 00000000 00:00 0
64dd4205000-64dd4206000 ---p 00000000 00:00 0
64dd4206000-64dd4207000 rwxp 00000000 00:00 0
64dd4207000-64dd4300000 ---p 00000000 00:00 0
64dd4300000-64dd4305000 rw-p 00000000 00:00 0
64dd4305000-64dd4306000 ---p 00000000 00:00 0
64dd4306000-64dd4307000 rwxp 00000000 00:00 0
64dd4307000-64dd4400000 ---p 00000000 00:00 0
64dd4400000-64dd4405000 rw-p 00000000 00:00 0
64dd4405000-64dd4406000 ---p 00000000 00:00 0
64dd4406000-64dd4407000 rwxp 00000000 00:00 0
64dd4407000-64dd4500000 ---p 00000000 00:00 0
64dd4500000-64dd4505000 rw-p 00000000 00:00 0
64dd4505000-64dd4506000 ---p 00000000 00:00 0
64dd4506000-64dd45ff000 rwxp 00000000 00:00 0
64dd45ff000-64df4049000 ---p 00000000 00:00 0
6d3fa7f8000-6d3fa838000 rw-p 00000000 00:00 0
6d3fa838000-6d3fabf8000 ---p 00000000 00:00 0
e6758100000-e6758200000 rw-p 00000000 00:00 0
100aa2b00000-100aa2c00000 rw-p 00000000 00:00 0
17877e500000-17877e600000 rw-p 00000000 00:00 0
2120ee94b000-2120ee980000 ---p 00000000 00:00 0
2120ee980000-2120ee9a0000 rw-p 00000000 00:00 0
2120ee9a0000-2120ee9ab000 ---p 00000000 00:00 0
297ddc000000-297ddc400000 rw-p 00000000 00:00 0
297ddc400000-297ddd000000 ---p 00000000 00:00 0
297ddd000000-297ddd400000 rw-p 00000000 00:00 0
297ddd400000-297dde000000 ---p 00000000 00:00 0
2a01dd300000-2a01dd400000 rw-p 00000000 00:00 0
34dedd900000-34dedda00000 rw-p 00000000 00:00 0
34e81d87c000-34e81d89c000 rw-p 00000000 00:00 0
34e81d89c000-34e81da7c000 ---p 00000000 00:00 0
7f5888000000-7f5888023000 rw-p 00000000 00:00 0
7f5888023000-7f588c000000 ---p 00000000 00:00 0
7f5890000000-7f58902dc000 rw-p 00000000 00:00 0
7f58902dc000-7f5894000000 ---p 00000000 00:00 0
7f5894000000-7f5894023000 rw-p 00000000 00:00 0
7f5894023000-7f5898000000 ---p 00000000 00:00 0
7f5898000000-7f5898237000 rw-p 00000000 00:00 0
7f5898237000-7f589c000000 ---p 00000000 00:00 0
7f589c000000-7f589c26e000 rw-p 00000000 00:00 0
7f589c26e000-7f58a0000000 ---p 00000000 00:00 0
7f58a0000000-7f58a02db000 rw-p 00000000 00:00 0
7f58a02db000-7f58a4000000 ---p 00000000 00:00 0
7f58a5ffc000-7f58a5ffd000 ---p 00000000 00:00 0
7f58a5ffd000-7f58a67fd000 rw-p 00000000 00:00 0                          [stack:30062]
7f58a67fd000-7f58a67fe000 ---p 00000000 00:00 0
7f58a67fe000-7f58a6ffe000 rw-p 00000000 00:00 0                          [stack:30061]
7f58a6ffe000-7f58a6fff000 ---p 00000000 00:00 0
7f58a6fff000-7f58a77ff000 rw-p 00000000 00:00 0                          [stack:30060]
7f58a77ff000-7f58a7800000 ---p 00000000 00:00 0
7f58a7800000-7f58a8000000 rw-p 00000000 00:00 0                          [stack:30059]
7f58a8000000-7f58a8023000 rw-p 00000000 00:00 0
7f58a8023000-7f58ac000000 ---p 00000000 00:00 0
7f58ac078000-7f58ac0d3000 r-xp 00000000 fd:01 19352035                   /home/t/test/node_modules/libxslt/build/Release/node-libxslt.node
7f58ac0d3000-7f58ac2d2000 ---p 0005b000 fd:01 19352035                   /home/t/test/node_modules/libxslt/build/Release/node-libxslt.node
7f58ac2d2000-7f58ac2d3000 r--p 0005a000 fd:01 19352035                   /home/t/test/node_modules/libxslt/build/Release/node-libxslt.node
7f58ac2d3000-7f58ac2d5000 rw-p 0005b000 fd:01 19352035                   /home/t/test/node_modules/libxslt/build/Release/node-libxslt.node
7f58ac2d5000-7f58ac474000 r-xp 00000000 fd:01 35554380                   /home/t/test/node_modules/libxslt/node_modules/libxmljs-mt/build/Release/xmljs.node
7f58ac474000-7f58ac674000 ---p 0019f000 fd:01 35554380                   /home/t/test/node_modules/libxslt/node_modules/libxmljs-mt/build/Release/xmljs.node
7f58ac674000-7f58ac67c000 r--p 0019f000 fd:01 35554380                   /home/t/test/node_modules/libxslt/node_modules/libxmljs-mt/build/Release/xmljs.node
7f58ac67c000-7f58ac680000 rw-p 001a7000 fd:01 35554380                   /home/t/test/node_modules/libxslt/node_modules/libxmljs-mt/build/Release/xmljs.node
7f58ac680000-7f58ac682000 rw-p 00000000 00:00 0
7f58ac682000-7f58ac685000 r-xp 00000000 fd:01 2339304                    /home/t/test/node_modules/segfault-handler/build/Release/segfault-handler.node
7f58ac685000-7f58ac884000 ---p 00003000 fd:01 2339304                    /home/t/test/node_modules/segfault-handler/build/Release/segfault-handler.node
7f58ac884000-7f58ac885000 r--p 00002000 fd:01 2339304                    /home/t/test/node_modules/segfault-handler/build/Release/segfault-handler.node
7f58ac885000-7f58ac886000 rw-p 00003000 fd:01 2339304                    /home/t/test/node_modules/segfault-handler/build/Release/segfault-handler.node
7f58ac886000-7f58ac887000 ---p 00000000 00:00 0
7f58ac887000-7f58ad087000 rw-p 00000000 00:00 0                          [stack:30058]
7f58ad087000-7f58ad088000 ---p 00000000 00:00 0
7f58ad088000-7f58ad888000 rw-p 00000000 00:00 0                          [stack:30057]
7f58ad888000-7f58ad889000 ---p 00000000 00:00 0
7f58ad889000-7f58ae089000 rw-p 00000000 00:00 0                          [stack:30056]
7f58ae089000-7f58ae08a000 ---p 00000000 00:00 0
7f58ae08a000-7f58ae88a000 rw-p 00000000 00:00 0                          [stack:30055]
7f58ae88a000-7f58aea40000 r-xp 00000000 fd:01 33697001                   /usr/lib64/libc-2.17.so
7f58aea40000-7f58aec40000 ---p 001b6000 fd:01 33697001                   /usr/lib64/libc-2.17.so
7f58aec40000-7f58aec44000 r--p 001b6000 fd:01 33697001                   /usr/lib64/libc-2.17.so
7f58aec44000-7f58aec46000 rw-p 001ba000 fd:01 33697001                   /usr/lib64/libc-2.17.so
7f58aec46000-7f58aec4b000 rw-p 00000000 00:00 0
7f58aec4b000-7f58aec61000 r-xp 00000000 fd:01 34882049                   /usr/lib64/libpthread-2.17.so
7f58aec61000-7f58aee61000 ---p 00016000 fd:01 34882049                   /usr/lib64/libpthread-2.17.so
7f58aee61000-7f58aee62000 r--p 00016000 fd:01 34882049                   /usr/lib64/libpthread-2.17.so
7f58aee62000-7f58aee63000 rw-p 00017000 fd:01 34882049                   /usr/lib64/libpthread-2.17.so
7f58aee63000-7f58aee67000 rw-p 00000000 00:00 0
7f58aee67000-7f58aee7c000 r-xp 00000000 fd:01 36385014                   /usr/lib64/libgcc_s-4.8.3-20140911.so.1
7f58aee7c000-7f58af07b000 ---p 00015000 fd:01 36385014                   /usr/lib64/libgcc_s-4.8.3-20140911.so.1
7f58af07b000-7f58af07c000 r--p 00014000 fd:01 36385014                   /usr/lib64/libgcc_s-4.8.3-20140911.so.1
7f58af07c000-7f58af07d000 rw-p 00015000 fd:01 36385014                   /usr/lib64/libgcc_s-4.8.3-20140911.so.1
7f58af07d000-7f58af17e000 r-xp 00000000 fd:01 34813712                   /usr/lib64/libm-2.17.so
7f58af17e000-7f58af37d000 ---p 00101000 fd:01 34813712                   /usr/lib64/libm-2.17.so
7f58af37d000-7f58af37e000 r--p 00100000 fd:01 34813712                   /PID 30054 received SIGSEGV for address: 0x100000074
/home/t/test/node_modules/segfault-handler/build/Release/segfault-handler.node(Aborted

Log2:

*** Error in `node': double free or corruption (!prev): 0x0000000002db8f30 ***
PID 30363 received SIGSEGV for address: 0x100000074
/home/t/test/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x1aca)[0x7ff3e93f4aca]
/lib64/libpthread.so.0(+0xf130)[0x7ff3eb9cb130]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x193f5)[0x7ff3e8e023f5]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(_ZN11ApplyWorker7ExecuteEv+0x43)[0x7ff3e8df9303]
node[0xfd11a1]
node[0xfdf449]
/lib64/libpthread.so.0(+0x7df5)[0x7ff3eb9c3df5]
/lib64/libc.so.6(clone+0x6d)[0x7ff3eb6f11ad]
PID 30363 received SIGSEGV for address: 0x100000074
/home/t/test/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x1aca)[0x7ff3e93f4aca]
PID 30363 received SIGSEGV for address: 0x100000074
/home/t/test/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x1aca)[0x7ff3e93f4aca]
/lib64/libpthread.so.0(+0xf130)[0x7ff3eb9cb130]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x193f5)[0x7ff3e8e023f5]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(_ZN11ApplyWorker7ExecuteEv+0x43)[0x7ff3e8df9303]
node[0xfd11a1]
/lib64/libpthread.so.0(+0xf130)[0x7ff3eb9cb130]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x193f5)[0x7ff3e8e023f5]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(_ZN11ApplyWorker7ExecuteEv+0x43)[0x7ff3e8df9303]
node[0xfd11a1]
node[0xfdf449]
node[0xfdf449]
/lib64/libpthread.so.0(+0x7df5)[0x7ff3eb9c3df5]
/lib64/libc.so.6(clone+0x6d)[0x7ff3eb6f11ad]

@gagern may be you can help with this strange error?:)

@gagern
Copy link
Collaborator

gagern commented Nov 8, 2015

Interesting. Can't reproduce the segfault here locally. Valgrind has lots of stuff to complain, though. Will have to enable debug symbols and see which of these reports could be related to this.

@tornillo
Copy link
Author

tornillo commented Nov 8, 2015

Can't reproduce the segfault here locally.

The above example does not cause an segfault on your environment?

@gagern
Copy link
Collaborator

gagern commented Nov 8, 2015

It didn't with node 4.1.1 in release mode, but it does now ith node 5.0.0 in debug mode. Not sure it's the version or build mode which is to blame. Might also be my other cpu usage, since it's likely related to asynchroneous execution. Running the thing through gdb, it seems as if some internal xml document data structures were no longer available. Which I'd take as an indication that the document has been cleaned by garbage collection while libxslt was still using it.

The instance indicated by gdb just now was somewhere in ApplyWorker. Looking at that, we see that there is a pointer to some docSource which is referred to using a libxmljs::XmlDocument* pointer. Not a JavaScript reference of some kind. If you look at the documentation for Nan::AsyncWorker you'll notice it has a number of functions called SaveToPersistent which simply store an object to a given key on some persistent object. Why yould one want to use that if you could as well use C++ members in a derived class? Because having the JavaScript objects stored in a persistent JavaScript object tells the V8 garbage collector that you're still using them. node-libxslt doesn't do so.

I'd say it's up to you whether you store JavaScript objects to the persistent storage and their contained native objects to additional members, or whether you use the persistent storage exclusively and unwrap objects from there during execution only. Either approach should work in my opinion, and the former should be less work in the short run. So I'd say take all the arguments to ApplyAsync in their raw JavaScript form without any unwrapping, and simply store them persistently with the worker, in addition to the existing processing. Will open a pull request for this.

@tornillo
Copy link
Author

tornillo commented Nov 8, 2015

With this PR my test example is now working fine, but my real application with big xsl-files keeps throwing segfault on synthetic highload tests...

/home/t/test/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x1aca)[0x7f260c060aca]
/lib64/libpthread.so.0(+0xf130)[0x7f260fe47130]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(xsltEvalAVT+0x32)[0x7f260d28c222]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(xsltAttrListTemplateProcess+0xf5)[0x7f260d2a3a55]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x12123)[0x7f260d277123]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x11ef6)[0x7f260d276ef6]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x11ef6)[0x7f260d276ef6]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x15832)[0x7f260d27a832]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(xsltProcessOneNode+0x78)[0x7f260d27af08]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(xsltApplyTemplates+0x4cc)[0x7f260d27bc4c]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x11ef6)[0x7f260d276ef6]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x15832)[0x7f260d27a832]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(xsltProcessOneNode+0x78)[0x7f260d27af08]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x1990b)[0x7f260d27e90b]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(_ZN11ApplyWorker7ExecuteEv+0x43)[0x7f260d2754d3]
PID 5588 received SIGSEGV for address: 0x78
/home/t/test/node_modules/segfault-handler/build/Release/segfault-handler.node(+0x1aca)[0x7f260c060aca]
/lib64/libpthread.so.0(+0xf130)[0x7f260fe47130]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(xsltEvalAVT+0x32)[0x7f260d28c222]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(xsltAttrListTemplateProcess+0xf5)[0x7f260d2a3a55]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x12123)[0x7f260d277123]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x11ef6)[0x7f260d276ef6]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x11ef6)[0x7f260d276ef6]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x15832)[0x7f260d27a832]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(xsltProcessOneNode+0x78)[0x7f260d27af08]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(xsltApplyTemplates+0x4cc)[0x7f260d27bc4c]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x11ef6)[0x7f260d276ef6]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x15832)[0x7f260d27a832]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(xsltProcessOneNode+0x78)[0x7f260d27af08]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(+0x1990b)[0x7f260d27e90b]
/home/t/test/node_modules/libxslt/build/Release/node-libxslt.node(_ZN11ApplyWorker7ExecuteEv+0x43)[0x7f260d2754d3]
node[0xfd11a1]
node[0xfdf449]
/lib64/libpthread.so.0(+0x7df5)[0x7f260fe3fdf5]
/lib64/libc.so.6(clone+0x6d)[0x7f260fb6d1ad]
node[0xfd11a1]
node[0xfdf449]
/lib64/libpthread.so.0(+0x7df5)[0x7f260fe3fdf5]
/lib64/libc.so.6(clone+0x6d)[0x7f260fb6d1ad]

@gagern
Copy link
Collaborator

gagern commented Nov 8, 2015

Can you try some of this:

cd node_modules/libxmljs-mt
node-gyp rebuild -d
ln -s Debug build/Release
cd -
node-gyp rebuild -d

This should enable debug symbols for libxmljs and node-libxslt. Hopefully this will give us a line number for the segfault. It would be even better if you could attach gdb to the process, one way or another. And when the segfault occurs, see exactly what data structure is affected.

Of course, it would also be nice to have a small reproducing example, like the previous one, so I can try that out for myself.

@tornillo
Copy link
Author

tornillo commented Nov 8, 2015

@gagern thank you for clarification of points to debug!
I'll try to attach gdb a bit later, but for now here's a new test example, which throws segfault at every run in my development environment (NodeJS 5.0.0)

require('segfault-handler').registerHandler('crash.log');

var libxslt = require('libxslt');
var xml = '<?xml version="1.0" encoding="utf-8"?>\n<root></root>';
var transform = function () {
    libxslt.parseFile('./test.xsl', function (err, xslObject) {
        xslObject.apply(xml, function (err, result) {});
    });
}

var counter = 1e3;

while (counter--) {
    transform();
}

test.xsl

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
    <xsl:apply-templates select="root" >
        <xsl:with-param name="total">1000</xsl:with-param>
    </xsl:apply-templates>
</xsl:template>

<xsl:template match="root">
    <xsl:param name="current">1</xsl:param>
    <xsl:param name="total" />

    <xsl:value-of select="generate-id()" />

    <xsl:if test="$current &lt; $total">
        <xsl:apply-templates select="../root">
            <xsl:with-param name="current" select="$current + 1" />
            <xsl:with-param name="total" select="$total" />
        </xsl:apply-templates>
    </xsl:if>
</xsl:template>

</xsl:stylesheet>

@gagern
Copy link
Collaborator

gagern commented Nov 9, 2015

I can reproduce this.

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffefd87700 (LWP 23189)]
0x00007ffff43a098d in xmlStrEqual (
    str1=0x7475223d676e6965 <error: Cannot access memory at address 0x7475223d676e6965>,
    str2=0x7fffefdeb820 "http://www.w3.org/1999/XSL/Transform")
    at ../vendor/libxml/xmlstring.c:162
162         if (*str1++ != *str2) return(0);
(gdb) bt
#0  0x00007ffff43a098d in xmlStrEqual (str1=0x7475223d676e6965 <error: Cannot access memory at address 0x7475223d676e6965>, str2=0x7fffefdeb820 "http://www.w3.org/1999/XSL/Transform") at ../vendor/libxml/xmlstring.c:162
#1  0x00007fffefda6eba in xsltApplySequenceConstructor (ctxt=0x7fffd4de61b8, contextNode=0x1d81fe8, list=0x12d3138, templ=0x0) at ../deps/libxslt/libxslt/transform.c:2616
#2  0x00007fffefdad1d2 in xsltIf (ctxt=0x7fffd4de61b8, contextNode=0x1d81fe8, inst=0x12d2ec8, castedComp=0x7fffd8001a38) at ../deps/libxslt/libxslt/transform.c:5464
#3  0x00007fffefda7033 in xsltApplySequenceConstructor (ctxt=0x7fffd4de61b8, contextNode=0x1d81fe8, list=0x12cc478, templ=0x7fffd8003608) at ../deps/libxslt/libxslt/transform.c:2647
#4  0x00007fffefda80be in xsltApplyXSLTTemplate (ctxt=0x7fffd4de61b8, contextNode=0x1d81fe8, list=0x12cc478, templ=0x7fffd8003608, withParams=0x7fffd4e31ee8) at ../deps/libxslt/libxslt/transform.c:3108
#5  0x00007fffefda6888 in xsltProcessOneNode (ctxt=0x7fffd4de61b8, contextNode=0x1d81fe8, withParams=0x7fffd4e31ee8) at ../deps/libxslt/libxslt/transform.c:2097
#6  0x00007fffefdac910 in xsltApplyTemplates (ctxt=0x7fffd4de61b8, node=0x1d81fe8, inst=0x12d3138, castedComp=0x7fffd8001b98) at ../deps/libxslt/libxslt/transform.c:5141
#7  0x00007fffefda7033 in xsltApplySequenceConstructor (ctxt=0x7fffd4de61b8, contextNode=0x1d81fe8, list=0x12d3138, templ=0x0) at ../deps/libxslt/libxslt/transform.c:2647
#8  0x00007fffefdad1d2 in xsltIf (ctxt=0x7fffd4de61b8, contextNode=0x1d81fe8, inst=0x12d2ec8, castedComp=0x7fffd8001a38) at ../deps/libxslt/libxslt/transform.c:5464
#9  0x00007fffefda7033 in xsltApplySequenceConstructor (ctxt=0x7fffd4de61b8, contextNode=0x1d81fe8, list=0x12cc478, templ=0x7fffd8003608) at ../deps/libxslt/libxslt/transform.c:2647
#10 0x00007fffefda80be in xsltApplyXSLTTemplate (ctxt=0x7fffd4de61b8, contextNode=0x1d81fe8, list=0x12cc478, templ=0x7fffd8003608, withParams=0x7fffd4e31c38) at ../deps/libxslt/libxslt/transform.c:3108
#11 0x00007fffefda6888 in xsltProcessOneNode (ctxt=0x7fffd4de61b8, contextNode=0x1d81fe8, withParams=0x7fffd4e31c38) at ../deps/libxslt/libxslt/transform.c:2097
#12 0x00007fffefdac910 in xsltApplyTemplates (ctxt=0x7fffd4de61b8, node=0x1d81fe8, inst=0x12d3138, castedComp=0x7fffd8001b98) at ../deps/libxslt/libxslt/transform.c:5141
#13 0x00007fffefda7033 in xsltApplySequenceConstructor (ctxt=0x7fffd4de61b8, contextNode=0x1d81fe8, list=0x12d3138, templ=0x0) at ../deps/libxslt/libxslt/transform.c:2647
#14 0x00007fffefdad1d2 in xsltIf (ctxt=0x7fffd4de61b8, contextNode=0x1d81fe8, inst=0x12d2ec8, castedComp=0x7fffd8001a38) at ../deps/libxslt/libxslt/transform.c:5464
#15 0x00007fffefda7033 in xsltApplySequenceConstructor (ctxt=0x7fffd4de61b8, contextNode=0x1d81fe8, list=0x12cc478, templ=0x7fffd8003608)

This is part of a 1500+ frame stack trace. The depth of which might be contributing to the problem in some way I don't understand yet. Frame 2 happens at transform.c:2616 inside the expansion of IS_XSLT_ELEM. So I'd say the problem occurs while the application is looking at the XSLT document, not the XML input. For some reason, some part of it apparently has disappeared – again. Needs more investigation, but I guess as one of my next steps I'd try to generate some output when the XML document gets freed, to see whether any document gets completely freed even though it's still in use.

@gagern
Copy link
Collaborator

gagern commented Nov 15, 2015

Not resolved, as indicated by #28 (comment) and subsequent comments.

@gagern gagern reopened this Nov 15, 2015
@gagern
Copy link
Collaborator

gagern commented Nov 15, 2015

I'd guess that the remaining issue is because the stylesheet refers to the xml document from which it was constructed, but on the v8 level the stylesheet object doesn't preserve a reference to the xml document object. Note the comment in the ~Stylesheet destructor:

// We can't free the stylesheet as the xml doc inside was probably
// already deleted by garbage collector and this results in segfaults

Well, that problem isn't restricted to the destructor alone; with enough memory pressure, the xml document will be gone by the time the stylesheet is used. I tried adding a Nan::Persistent reference from the stylesheet to the wrapper for the xml document. Doesn't work yet, still investigating why.

@gagern
Copy link
Collaborator

gagern commented Nov 15, 2015

@tornillo, would you please give #31 a try? On your small example it works fine.

@tornillo
Copy link
Author

@gagern With #31 highload test was successfully passed without segfaults on my project. Wow! Thank you!:)

@gagern
Copy link
Collaborator

gagern commented Nov 16, 2015

@tornillo A pleasure. Looking forward to the next release here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants