error on doing "Truffle init" - node.js

I am new to smart contract programming, recently installed truffle using npm on Node(version: 6.10.3)
When I run the command truffle init first time, I received this error:
events.js:160
throw er; // Unhandled 'error' event
^
Error: connect ETIMEDOUT 151.101.8.133:443
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
The next time I run truffle init, I got ths error:
events.js:160
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at exports._errnoException (util.js:1018:11)
at TLSWrap.onread (net.js:568:26)
Any idea on how to resolve this

I was also facing a similar issue when I tried to execute truffle init behind a corporate http proxy and found a workaround.
Modified the cli.bundled.js: replaced https.request with request
Diff:
diff --git a/build/cli.bundled.js b/build/cli.bundled.js
index 01c69e3..aa2605c 100755
--- a/build/cli.bundled.js
+++ b/build/cli.bundled.js
## -202412,12 +202412,8 ## var Init = {
// will fail spectacularly in a way we can't catch, so we have to do it ourselves.
return new Promise(function(accept, reject) {
- var options = {
- method: 'HEAD',
- host: 'raw.githubusercontent.com',
- path: '/trufflesuite/' + expected_full_name + "/master/truffle.js"
- };
- req = https.request(options, function(r) {
+ var request = require('request');
+ request({ method: 'HEAD', uri: 'https://raw.githubusercontent.com/trufflesuite/'+expected_full_name+'/master/truffle.js'}, function (error, r, body) {
if (r.statusCode == 404) {
return reject(new Error("Example '" + name + "' doesn't exist. If you believe this is an error, please contact Truffle support."));
} else if (r.statusCode != 200) {
## -202425,7 +202421,6 ## var Init = {
}
accept();
});
- req.end();
});
}).then(function() {
## -212634,4 +212629,4 ## module.exports = require("solc");
module.exports = require("string_decoder");
/***/ })
-/******/ ]);
\ No newline at end of file
+/******/ ]);
Prerequisite:
Install request via npm (npm install -g request)
Proxy - setup enviroment as described here

Without code it is pretty difficult to say where this goes wrong. But do you have a ethereum rpc node running on the port specified in the truffle configuration.
Truffle configuration
When inspecting your error code I see you try to connect to 151.101.8.133:443 is there an rpc node running on this port?

Related

How can I gracefully handle a failed tcpSocket.connect attempt?

The following code causes an error when there is no existing TCP server to communicate with on the specified host:
const net = require('net');
const argv = require('minimist')(process.argv.slice(2));
try {
var tcpSocket = new net.Socket();
tcpSocket.connect(argv.tcpport, argv.tcphost, function onConnected() {
console.log('connected');
tcpSocket.on('data', function onIncoming(data) {
console.log(data);
});
tcpSocket.on('close', function onClose(data) {
tcpSocketConnected = false;
});
tcpSocketConnected = true;
});
} catch (err) {
console.log("PRINT ME: ", err);
}
Error:
events.js:183
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED 127.0.0.1:1906
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
I am unable to catch the error even though I wrap the code in a try...catch.
Why does my catch block not catch the error?
How can I gracefully handle the error?
You should be able to explicitly handle the error event using event emitter api (same way as you handled close and data):
tcpSocket.on('error', handleError)
From Docs:
Event: 'error'#
Added in: v0.1.90
<Error>
Emitted when an error occurs. Unlike net.Socket, the 'close' event
will not be emitted directly following this event unless server.close()
is manually called. See the example in discussion of server.listen().

Sync gateway connection Error: connect EMFILE - Local (undefined:undefined)

I am trying to get couchbase document revision identifier via sync gatetway API GET /{db}/{doc} within Node server:
function _getRev(docIdUrl, gateway, callback) {
let options = {
host: gateway.host,
path: gateway.path + docIdUrl,
port: gateway.port,
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
};
// Node HTTP requests
let syncGatewayRequest = http.request(options, (response) => {
// ...unrelevant codes
});
syncGatewayRequest.on('error', (error) => {
logger.error('syncGateway connection error for ' + docIdUrl);
callback(error, null); // here is the error happening!!!!!
});
syncGatewayRequest.write(JSON.stringify({}));
syncGatewayRequest.end();
}
Then I got error:
[2017-11-03 11:07:51.961] { [Error: connect EMFILE 10.0.1.53:4985 - Local (undefined:undefined)]
code: 'EMFILE',
errno: 'EMFILE',
syscall: 'connect',
address: '10.0.1.53',
port: 4985 }
Error: connect EMFILE 10.0.1.53:4985 - Local (undefined:undefined)
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at connect (net.js:849:16)
at net.js:937:9
at nextTickCallbackWith0Args (node.js:420:9)
at process._tickCallback (node.js:349:13)
There is a context that the above function are executed asynchronously by a significant number of services, say 10,000+
I noticed the post here Nodejs connect EMFILE - How to reuse connections?
But I tried to unlimit the default connections by doing:
var http = require('http')
http.globalAgent.maxSockets = Infinity
But does not seem to work, error still ...
Anyone can let me know what's wrong here?

Node.js Error : connect ECONN Refused

I am new to Node.js and am unable to resolve this error:
Error: connect ECONNREFUSED
at errnoException (net.js:901:11)
at Object.afterConnect (as oncomplete) (net.js:892)
The code I was trying out follows :
var async = require('async'),
request = require('request');
function done(err,results) {
if (err) {
throw err;
}
console.log('Done ! results: %j',results);
}
var collection = [1,2,3,4];
function iterator(value,callback) {
request.post({
url: 'http://localhost:8080',
body: JSON.stringify(value)
}, function (err,res,body){
if (err) {
callback(err,body && JSON.parse(body));
}
});
}
async.map(collection,iterator,done);
ECONNREFUSED – Connection refused by server error
A port is being blocked can be the root cause of this issue, check if your connection is being blocked or even the changed default port can also cause this issue. Identify which app/service you are connecting to and its port is being blocked or changed.
And in your case check whether the application is hosted on port: 8080 or not.
But, this most likely occurs with FileZilla.

Coffeescript HTTP client

I am running server.coffee from this page: https://github.com/xenph/foaas
From the command line, you can do:
curl http://localhost:5000/off/Name1/Name2
!##$ off, Name1. - Name2
But I'm using the code from this page: http://coffeescriptcookbook.com/chapters/networking/basic-http-client
http = require 'http'
http.get { host: 'http://localhost:5000/off/Name1/Name2' }, (res) ->
data = ''
res.on 'data', (chunk) ->
data += chunk.toString()
res.on 'end', () ->
console.log data
The error I get is:
events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
Which leads me to believe that it's not finding the url.
What can I do?
try
http.get 'http://localhost:5000/off/Name1/Name2', (res) ->
or
http.get { hostname: 'localhost', port: 5000, path: '/off/Name1/Name2' }, (res) ->
instead of
http.get { host: 'http://localhost:5000/off/Name1/Name2' }, (res) ->
maybe?
Firstly extract a little more info from exceptions:
.on('error',function(e){
console.log("Error: " + hostNames[i] + "\n" + e.message);
console.log( e.stack );
});
Secondly as curl is working we can assume that the service is up and accessible from localhost so there must be a deeper issue. What flavour of linux are you using? I've solved similar issues before by disabling firewall (iptables) and selinux.
Also double check to make sure that you have dns configured and that it will return 127.0.0.1 for localhost. Use nslookup.

Getting error while using http in node.js

Below is the error getting while calling http get request
events.js:66
throw arguments[1]; // Unhandled 'error' event
^
Error: getaddrinfo ENOENT
at errnoException (dns.js:31:11)
at Object.onanswer [as oncomplete] (dns.js:123:16)
PFB my code throwing the error
var options = {
host: 'http://xyz.com',
port: 80,
path : 'test?query=' + escape(req.params.searchTerm) + '&offset=0&hits=500',
method: 'GET',
headers: {
Cookie : "session=" + session
}
};
console.log("Start");
var x = http.request(options,function(subRes){
console.log("Connected");
subRes.on('data',function(data){
console.log("===================data===" +util.inspect(data));
});
});
x.end();
Any ideas, why this error ?
ENOENT is an error that indications name resolution did not return any results. You specify the hostname as http://xyz.com, but colons are not allowed in hostnames. You want:
var options = {
host: 'xyz.com',
You specify the host as http://xyz.com, which should just be xyz.com.
This value is used to resolve the IP address of the host you're trying to connect to using DNS.

Resources