Comments (18)
Can you post the code that caused the segfault?
Also the libcurl version.
from node-libcurl.
Libcurl version: libcurl3:amd64 (7.26.0-1+wheezy13). And here comes the code fragment:
function processRequest(method, options, callback) {
var responseHeaders = [ ];
var responseStatus = 0;
var responseBody = [ ];
var callbackCalled = false;
var headers = JSON.parse(JSON.stringify(globalHeaders)); // Cloning object
var cookieString = cookiejar.getCookieStringSync(options.url);
if (cookieString) {
headers.push('Cookie: ' + cookieString);
}
if (referer) {
headers.push('Referer: ' + referer);
}
if (options.contentType) {
headers.push('Content-Type: ' + options.contentType);
} else if (method == 'POST') {
headers.push('Content-Type: application/x-www-form-urlencoded');
}
var curl = new Curl();
curl.setOpt(Curl.option.URL, options.url);
curl.setOpt(Curl.option.TIMEOUT, config.timeout);
curl.setOpt(Curl.option.CONNECTTIMEOUT, config.connectTimeout);
curl.setOpt(Curl.option.LOW_SPEED_TIME, config.timeout);
curl.setOpt(Curl.option.LOW_SPEED_LIMIT, 512);
curl.setOpt(Curl.option.NOPROGRESS, true);
curl.setOpt(Curl.option.HTTPHEADER, headers);
if (method == 'POST') {
curl.setOpt(Curl.option.POST, true);
curl.setOpt(Curl.option.POSTFIELDS, options.postData);
}
curl.setOpt(Curl.option.FOLLOWLOCATION, config.allowRedirect);
curl.setOpt(Curl.option.SSL_VERIFYHOST, false);
curl.setOpt(Curl.option.SSL_VERIFYPEER, false);
curl.setOpt(Curl.option.ACCEPT_ENCODING, 'gzip');
if (config.httpProxy) {
curl.setOpt(Curl.option.PROXY, config.httpProxy);
}
curl.on('header', handleHeader);
curl.on('error', handleError);
curl.on('data', handleBody);
curl.on('end', handleFinish);
curl.perform();
function handleError(error) {
finishError(error.message);
}
function handleHeader(chunk) {
var header = chunk.toString().replace("\r", '').replace("\n", '');
if(chunk.length > 2) {
if(header.substr(0, 4) === 'HTTP') {
var status = header.split(' ');
responseStatus = status[1];
} else {
responseHeaders.push(header);
}
}
return chunk.length;
}
function handleBody(chunk) {
responseBody.push(chunk);
return chunk.length;
}
function handleFinish() {
var result = {
status: responseStatus, // curl.getInfo('RESPONSE_CODE'),
contentType: curl.getInfo('CONTENT_TYPE'),
headers: responseHeaders,
body: Buffer.concat(responseBody),
proxy: config.httpProxy
};
for (var i in responseHeaders) {
if(!responseHeaders.hasOwnProperty(i)) continue;
var header = responseHeaders[i];
if(/Set\-Cookie:/.test(header)) {
var cookie = Cookie.parse(header.replace('Set-Cookie:', '').trim());
cookiejar.setCookieSync(cookie, options.url);
}
}
finishSuccess(result);
}
function finishSuccess(result) {
finish(null, result);
}
function finishError(error) {
finish({ message: error, url: options.url, proxy: config.httpProxy });
}
function finish(error, result) {
if(callbackCalled) {
throw 'trying to send callback twice: ' + options.url;
}
curl.close();
callbackCalled = true;
if(error) {
callback(error, null);
} else {
callback(null, result);
}
}
}
from node-libcurl.
I cannot reproduce the segfault.
Can you post a code that causes it without other dependencies?
from node-libcurl.
I cannot simply isolate this code, because of very high usage. Looks like this is somehow related to timeout processing.
from node-libcurl.
Tried again today, but could not trigger it, I will leave this open for now.
from node-libcurl.
I got the same segfault error in version 0.7.0:
Stack trace of thread 11101:
#0 0x00007f6cc0714ee1 _ZN11NodeLibcurl5Multi21CallOnMessageCallbackEPv8CURLcode (node_libcurl.node)
#1 0x00007f6cc071518f _ZN11NodeLibcurl5Multi15ProcessMessagesEv (node_libcurl.node)
#2 0x00007f6cc07152d7 _ZN11NodeLibcurl5Multi13HandleTimeoutEPvlS1_ (node_libcurl.node)
#3 0x00007f6cc04bae75 update_timer (libcurl.so.4)
#4 0x00007f6cc04be0f8 curl_multi_socket_action (libcurl.so.4)
#5 0x00007f6cc0715251 _ZN11NodeLibcurl5Multi9OnTimeoutEP10uv_timer_si (node_libcurl.node)
#6 0x00007f6cc07152d7 _ZN11NodeLibcurl5Multi13HandleTimeoutEPvlS1_ (node_libcurl.node)
#7 0x00007f6cc04bae75 update_timer (libcurl.so.4)
#8 0x00007f6cc04be0f8 curl_multi_socket_action (libcurl.so.4)
#9 0x00007f6cc0715251 _ZN11NodeLibcurl5Multi9OnTimeoutEP10uv_timer_si (node_libcurl.node)
#10 0x00007f6cc07152d7 _ZN11NodeLibcurl5Multi13HandleTimeoutEPvlS1_ (node_libcurl.node)
#11 0x00007f6cc04bae75 update_timer (libcurl.so.4)
#12 0x00007f6cc04bc524 curl_multi_add_handle (libcurl.so.4)
#13 0x00007f6cc071550d _ZN11NodeLibcurl5Multi9AddHandleERKN3Nan20FunctionCallbackInfoIN2v85ValueEEE (node_libcurl.node)
#14 0x00007f6cc07131d1 _ZN3Nan3impL23FunctionCallbackWrapperERKN2v89ArgumentsE (node_libcurl.node)
#15 0x00000b4af6e56e59 n/a (n/a)
on fedora 23 libcurl 7.43.0
the code using node-libcurl:
var curl = new Curl();
curl.setOptObject(options);
curl.on('end', function(statusCode, body, headers) {
var output = {url: url, html: body};
callback(null, statusCode, output);
this.close();
});
curl.on('error', function(err, errCode){
callback({messsage: err.message, code: errCode});
this.close();
});
curl.perform();
from node-libcurl.
@TariqAbugofa can you post the setOptObject
function body, and what was the value of options
?
from node-libcurl.
I added the function to curl prototype:
Curl.prototype.setOptObject = function(opts) {
for (var opt in opts) {
if (opts[opt] !== undefined) this.setOpt(App.Curl.option[opt], opts[opt]);
}
};
the options:
options = {
MAXREDIRS: 3,
FOLLOWLOCATION: true,
CONNECTTIMEOUT: 30,
USERAGENT: random_ua.generate()
TIMEOUT: 30,
COOKIEJAR: __dirname+"/cookie.txt",
COOKIEFILE: __dirname+"/cookie.txt",
PROXY: ''
};
random_ua is a node library to generate random user agents
from node-libcurl.
Sorry, but I still cannot reproduce.
The folloing worked correctly without any issues:
var Curl = require( 'node-libcurl' ).Curl,
random_ua = require( 'random-ua' ),
curl = new Curl();
Curl.prototype.setOptObject = function(opts) {
for ( var opt in opts ) {
if ( opts[opt] !== undefined ) this.setOpt( Curl.option[opt], opts[opt] );
}
};
var options = {
MAXREDIRS: 3,
FOLLOWLOCATION: true,
CONNECTTIMEOUT: 30,
USERAGENT: random_ua.generate(),
TIMEOUT: 30,
COOKIEJAR: __dirname + '/cookie.txt',
COOKIEFILE: __dirname + '/cookie.txt',
PROXY: '',
URL : 'http://github.com'
};
curl.setOptObject( options );
curl.on( 'header', function ( data ) {
console.log( data.toString() );
});
curl.on('end', function( statusCode, body, headers ) {
var output = { url: options.url, html: body };
console.log( null, statusCode, output );
this.close();
});
curl.on( 'error', function( err, errCode ) {
console.log( {messsage: err.message, code: errCode} );
this.close();
});
curl.perform();
Fedora 23 x64
node 4
libcurl 7.43
The callback
function you guys are using is probably doing something strange.
from node-libcurl.
I know, its hard to reproduce. It's happening with me once every thousands of url calls. I found urls that caused the crash and when I try them again it works perfectly. there is no clear scenario for this.
from node-libcurl.
@JCMais I also get this, the curl just throw "Segmentation fault (core dumped)" (permanently)
-
gcc 4.8
-
CentOS release 6.7 (Final)
-
libcurl 7.47.1
I had 2 gcc version, once 4.4.7 and 4.8, I did try to override the 4.4.7 by 4.8 and able to rebuild from source (thats confirm that gcc 4.8 being used)
sudo ln -s /opt/rh/devtoolset-2/root/usr/bin/* /usr/bin/
However still get the segment error.
var Curl = require('node-libcurl').Curl;
var curl = new Curl();
var API_EP = "http://google.com"
var response = "";
var ret = {
success: 0,
message: "Unknown"
};
curl.setOpt(Curl.option.URL, API_EP);
curl.setOpt(Curl.option.CONNECTTIMEOUT, 10);
curl.setOpt('SSL_VERIFYHOST', 0);
curl.setOpt('SSL_VERIFYPEER', 0);
curl.on('end', function (statusCode, body, headers) {
this.close();
ret.message = response;
console.log(ret);
});
curl.on('error', function (err, curlErrCode) {
var errr_msg = 'Err: ' + err + ". Code: " + curlErrCode;
ret.message = errr_msg;
console.log(ret);
this.close();
});
curl.on('data', function (chunk) {
response += chunk;
});
curl.perform();
from node-libcurl.
What is the node.js version? Are you using the latest addon (currently, 0.8.0) version?
If possible paste the stack trace of the segfault.
from node-libcurl.
Yes, node v0.10.42. Yes, latest addon, 0.8.0. Unfortunately all I see is the mesasge "Segmentation fault (core dumped)". My centos gcc have problem, because I am on 6.7, the "yum install npm" will default install the gcc 4.4.7, although I did export gcc path to 4.8.
from node-libcurl.
May I ask why are you installing npm via yum?
You can update npm running npm -g install npm@latest-2
.
I ran the code you posted and had no problems, but I'm using Debian 8 and gcc 4.9 to test it since I don't have a CentOS to test right now.
For the debugging, first, install the debug version of the addon, npm install node-libcurl --build-from-source --debug --verbose
.
Now run ulimit -c unlimited
, this enable the core dump to be created, run the code that causes the segfault again, this will create the core file. This file can be pretty big, so take note.
Now install gdb
(using your system package manager) and run the following (where core is the dump file created, it's probably called core and is in the current directory):
gdb path_to_node ./core
bt
quit
It has been a long time since I used gdb, so such commands above can be incorrect.
Paste all the logs in something like pastebin and post here.
from node-libcurl.
Hi @JCMais sorry for late response. I now able to solve the crash by remove npm (which also remove gcc 4.7.7), then re-install gcc 4.8, then install npm again.
Now I can build-from-source this node-libcurl again and run curl works good. I guess issue was a mess up on gcc on server
from node-libcurl.
@TariqAbugofa and @druidvav if you are still using the addon, is the segfault gone in the latest releases?
I want to release the v1 version in the next days, however I want to get this fixed (if it's not yet) first if possible.
from node-libcurl.
i've already upgraded to most recent version of nodejs and everything works fine.
from node-libcurl.
Thanks for the info @druidvav
Anyway, I probably fixed what was causing this, I will release a new version later today.
from node-libcurl.
Related Issues (20)
- How can I write a custom request asynchronously? HOT 1
- [feat] rewrite `node-libcurl` with, the **ONLY** isomorphic way, napi HOT 1
- Curl Easy segmentation fault with requests to external site HOT 3
- Expected npx node-libcurl $URL to work as curl $URL HOT 1
- TypeError: Class extends value #<Object> is not a constructor or null HOT 1
- HTTP_CONTENT_DECODING = false but still decodes the server's responses HOT 1
- How to make multiple curly instances maintain separate connections to same host? HOT 2
- unable to npm install HOT 3
- npm install issues. HOT 5
- libcurl vuln HOT 2
- Add prebuilt binaries for nodejs 20 LTS HOT 13
- read raw msg HOT 3
- Does node-libcurl support res_init? HOT 1
- Error after upgrade to Node 20.10 ...: ERR_DLOPEN_FAILED HOT 2
- SFTP / SSH stuck on login when using Curl/Multi and password auth HOT 2
- Curly - Close connection - Timeout Exception HOT 3
- Cannot install HOT 3
- Send binary data with HTTPPOST option HOT 1
- Hanging on PROTOCONNECTING
- Add prebuilt binaries for node 21(macOS) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-libcurl.