strongloop / strong-oracle

Deprecated: Node.js Driver for Oracle databases (Use https://github.com/oracle/node-oracledb instead)
Other
45 stars 18 forks source link

(Reader) Large tables throws segmentation fault node 0.11.13 #13

Closed soyuka closed 9 years ago

soyuka commented 10 years ago

Using the Reader as stated in node-oracle README with more than 10000 lines throws a segmentation fault with node 0.11.13.

I tried to debug it with https://github.com/ddopson/node-segfault-handler but it's not 0.11.13 gyp compatible. You may have suggestions on this?

I've managed to reproduce on 0.10.31:

PID 31956 received SIGSEGV for address: 0x0
./node_modules/segfault-handler/build/Release/segfault-handler.node(+0x10f5)[0x7ffc79e810f5]
/lib/x86_64-linux-gnu/libpthread.so.0(+0xf030)[0x7ffc85243030]
/usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1(kpufch0+0x86)[0x7ffc825e5094]
/usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1(kpufch+0x5ef)[0x7ffc825e3d4f]
/usr/lib/oracle/11.2/client64/lib/libclntsh.so.11.1(OCIStmtFetch+0xf)[0x7ffc82578c5f]
/usr/lib/oracle/11.2/client64/lib/libocci.so.11.1(_ZN6oracle4occi13ResultSetImpl4nextEj+0x2d7)[0x7ffc84afab33]
./node_modules/strong-oracle/build/Release/oracle_bindings.node(_ZN6Reader12EIO_NextRowsEP9uv_work_s+0xc2)[0x7ffc84ca25d2]
node[0x99bcc0]
node[0x991581]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x6b50)[0x7ffc8523ab50]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7ffc84f84e6d]
[1]    31956 abort      node index.js
gx0r commented 9 years ago

I get segfaults too on node v0.10.33 on Mac OS X Yosemite.

PID 94131 received SIGSEGV for address: 0x48 0 segfault-handler.node 0x00000001008d647f _ZL16segfault_handleriP9siginfoPv + 287 1 libsystem_platform.dylib 0x00007fff90d27f1a _sigtramp + 26 2 ??? 0x0000000000000000 0x0 + 0 3 libclntsh.dylib.11.1 0x0000000104a0412e kpufcpf + 8590 4 libclntsh.dylib.11.1 0x0000000104a0584c kpufch0 + 5052 5 libclntsh.dylib.11.1 0x0000000104a098c5 kpufch + 8757 6 libclntsh.dylib.11.1 0x0000000104bf0970 OCIStmtFetch + 96 7 libocci.dylib.11.1 0x00000001040443a3 _ZN6oracle4occi13ResultSetImpl4nextEj + 1497 8 oracle_bindings.node 0x00000001008e9389 _ZN6Reader12EIO_NextRowsEP9uv_work_s + 359 9 node 0x0000000100391757 worker + 90 10 node 0x0000000100387f32 uvthread_start + 25 11 libsystem_pthread.dylib 0x00007fff901d92fc _pthread_body + 131 12 libsystem_pthread.dylib 0x00007fff901d9279 _pthread_body + 0 13 libsystem_pthread.dylib 0x00007fff901d74b1 thread_start + 13

raymondfeng commented 9 years ago

Thank you for reporting the issue. I'll investigate.

Do you use reader.nextRows(count, callback) with a big count? or just reader.nextRow()?

gx0r commented 9 years ago

Thanks! Just reader.nextRow(). Here is my test case. FWIW, the database I connect to is on a remote box and rather slow (10 rows take maybe 0.3 second to retrieve). My program consistently segfaults after around 524 rows. Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

npm install express, segfault-handler, strong-oracle

app.js:

var SegfaultHandler = require('segfault-handler');
SegfaultHandler.registerHandler();

var fs = require('fs');
var http = require('http');

var db = {
  hostname: 'localhost',
  port: 1521,
  user: 'a',
  password: 'b',
  database: 'c',
}

var oracle = require('strong-oracle')();
var express = require('express');
var app = express();

app.use(express.static(__dirname + '/public'));

oracle.connect(db, function(err, connection) {

  console.log(connection);

  app.get('/users', function(req, res) {
    res.setHeader("Content-Type", "application/json");
    var reader = connection.reader(
      "select * from(SELECT * FROM USERS ORDER BY USERNAME) ", []
    );

    res.write("[");
    var first = true;

    var doRead = function(cb) {
      reader.nextRow(function(err, row) {
        if (err) return cb(err);
        if (row) {
          if (!first)
            res.write(",")
          res.write(JSON.stringify(row));
          first = false;
          return doRead(cb)
        } else {
          res.write("]");
          res.end();
          return cb();
        }
      });
    }

    doRead(function(err) {
      if (err) throw err; // or log it
      console.log("all records processed");
    });
  });

  app.listen(3000);

});
soyuka commented 9 years ago

Same here, I was using just reader.nextRow() to minimize memory footprint.

Basically doing exactly like @llambda !

gx0r commented 9 years ago

By the way, if I use "oracle" module instead of "strong-oracle", I don't get segfault.

raymondfeng commented 9 years ago

Fixed in strong-oracle@1.2.2.