Node.js MySQL ETIMEDOUT error - javascript

After running node for a long time I get this error.
My program itself works perfectly fine.
What does it really mean? I can't find anything about it.
And most importantly how to prevent it?
Error: read ETIMEDOUT
at errnoException (net.js:901:11)
at TCP.onread (net.js:556:19)
--------------------
at Query.Sequence (/nodejs/node_modules/mysql/lib/protocol/sequences/Sequence.js:15:20)
at new Query (/nodejs/node_modules/mysql/lib/protocol/sequences/Query.js:12:12)
at Function.Connection.createQuery (/nodejs/node_modules/mysql/lib/Connection.js:48:10)
at Connection.query (/nodejs/node_modules/mysql/lib/Connection.js:100:26)
at Socket.<anonymous> (/nodejs/server.js:23:12)
at Socket.EventEmitter.emit [as $emit] (events.js:95:17)
at SocketNamespace.handlePacket (/nodejs/node_modules/socket.io/lib/namespace.js:335:22)
at Manager.onClientMessage (/nodejs/node_modules/socket.io/lib/manager.js:488:38)
at WebSocket.Transport.onMessage (/nodejs/node_modules/socket.io/lib/transport.js:387:20)
at Parser.<anonymous> (/nodejs/node_modules/socket.io/lib/transports/websocket/hybi-16.js:39:10)
I guess it has to do something with the mysql I'm using in my program because it refers to Query.sequence or something.
https://github.com/felixge/node-mysql
The only line I can refer to that causes this error is where I create a query:
database.query("SELECT * FROM `...

Related

Why I get Access Denied error from Loopback4 while able to connect from MySql workbench using same credentials

I am trying to run todo list example in loopback 4. I use MySql as the backend db on a different server. The problem I am facing is while I could connect to the database from MySql Workbench, I get the following error when I try making the db connection from loopback 4 using the same credentials.
Any help is appreciated.
Connection fails: Error: ER_DBACCESS_DENIED_ERROR: Access denied for user 'dev1'#'%' to database 'todo'
It will be retried for the next request.
C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\sequences\Sequence.js:47
var err = new Error(code + ': ' + packet.message);
^
Error: ER_DBACCESS_DENIED_ERROR: Access denied for user 'dev1'#'%' to database 'todo'
at Handshake.Sequence._packetToError (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket.<anonymous> (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\Connection.js:91:28)
at Socket.<anonymous> (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\Connection.js:525:10)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead (internal/stream_base_commons.js:182:23)
--------------------
at Protocol._enqueue (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\Connection.js:119:18)
at Pool.getConnection (C:\Users\rames\GitHub\todo-list\node_modules\mysql\lib\Pool.js:48:16)
at MySQL.connect (C:\Users\rames\GitHub\todo-list\node_modules\loopback-connector-mysql\lib\mysql.js:90:17)
at Object.initializeDataSource [as initialize] (C:\Users\rames\GitHub\todo-list\node_modules\loopback-connector-mysql\lib\mysql.js:44:28)
at DbDataSource.DataSource.setup (C:\Users\rames\GitHub\todo-list\node_modules\loopback-datasource-juggler\lib\datasource.js:513:19)
at new DataSource (C:\Users\rames\GitHub\todo-list\node_modules\loopback-datasource-juggler\lib\datasource.js:145:8)
at new DbDataSource (C:\Users\rames\GitHub\todo-list\src\datasources\db.datasource.ts:20:5)
at C:\Users\rames\GitHub\todo-list\node_modules\#loopback\context\src\resolver.ts:73:14
at Object.transformValueOrPromise (C:\Users\rames\GitHub\todo-list\node_modules\#loopback\context\src\value-promise.ts:270:12)
at Object.instantiateClass (C:\Users\rames\GitHub\todo-list\node_modules\#loopback\context\src\resolver.ts:66:35)
at C:\Users\rames\GitHub\todo-list\node_modules\#loopback\context\src\binding.ts:533:29
at Binding._getValue (C:\Users\rames\GitHub\todo-list\node_modules\#loopback\context\src\binding.ts:410:14)
at C:\Users\rames\GitHub\todo-list\node_modules\#loopback\context\src\binding.ts:305:23
at C:\Users\rames\GitHub\todo-list\node_modules\#loopback\context\src\resolution-session.ts:114:13
I noticed there was a typo in database name in the connection string. I fixed it and I am able to connect now.
#jaromanda Thank you.

Error: Invalid JSON RPC response while using INFURA

getting error:While implementing ethereum blockchain code ,
error that i am getting is :Invalid JSON RPC response while using INFURA
Attaching error log below kindly help
Error: Invalid JSON RPC response: ""
at Object.InvalidResponse (/home/joshi/Desktop/inbox/node_modules/truffle-hdwallet-provider/node_modules/web3/lib/web3/errors.js:35:16)
at XMLHttpRequest.request.onreadystatechange (/home/joshi/Desktop/inbox/node_modules/truffle-hdwallet-provider/node_modules/web3/lib/web3/httpprovider.js:115:32)
at XMLHttpRequestEventTarget.dispatchEvent (/home/joshi/Desktop/inbox/node_modules/xhr2/lib/xhr2.js:64:18)
at XMLHttpRequest._setReadyState (/home/joshi/Desktop/inbox/node_modules/xhr2/lib/xhr2.js:354:12)
at XMLHttpRequest._onHttpRequestError (/home/joshi/Desktop/inbox/node_modules/xhr2/lib/xhr2.js:544:12)
at ClientRequest.<anonymous> (/home/joshi/Desktop/inbox/node_modules/xhr2/lib/xhr2.js:414:24)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at TLSSocket.socketErrorListener (_http_client.js:387:9)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:64:8)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
If you don't post more information, such as a little piece of code is difficult to understand what is happening.
What you should try is this:
In every link to infura api remove the "/v3" part from the url.
From this:
const provider = new HDWalletProvider(mnemonic,
'https://rinkeby.infura.io/v3/project_id');
To this:
const provider = new HDWalletProvider(mnemonic,
'https://rinkeby.infura.io/project_id');
Hope this helps.
Don't use www and /v3 in infura API URI and it's required to use https in the URI. eg.
https://rinkeby.infura.io/project_id

Postresql not connecting to heroku

im using heroku to host my site however it keeps spitting out the same error which is
2018-05-06T19:28:52.212104+00:00 app[web.1]:AssertionError [ERR_ASSERTION]: false == true
2018-05-06T19:28:52.212106+00:00 app[web.1]:at Object.exports.connect (_tls_wrap.js:1036:3)
2018-05-06T19:28:52.212107+00:00 app[web.1]: at Socket. (/app/node_modules/pg/lib/connection.js:94:23)
2018-05-06T19:28:52.212109+00:00 app[web.1]:at Object.onceWrapper (events.js:315:30)
2018-05-06T19:28:52.212110+00:00 app[web.1]:at emitOne (events.js:116:13)
2018-05-06T19:28:52.212112+00:00 app[web.1]: at Socket.emit (events.js:211:7)
2018-05-06T19:28:52.212113+00:00 app[web.1]:at addChunk (_stream_readable.js:263:12)
2018-05-06T19:28:52.212115+00:00 app[web.1]:at readableAddChunk (_stream_readable.js:250:11)
2018-05-06T19:28:52.212116+00:00 app[web.1]:at Socket.Readable.push (_stream_readable.js:208:10)
2018-05-06T19:28:52.212118+00:00 app[web.1]: at TCP.onread >>(net.js:607:20)
this is how im connecting (taken straight off of herokus website)
const { Client } = require("pg");
const router = express.Router();
const pool = new Client({
connectionString: process.env.DATABASE_URL,
ssl: true,
});
pool.connect();
I found out what the error was:
the error was that i did not have a db create. i decided to use elephantSQL and from their i connected to elephantSQL with pgadmin and recreated my database. it works perfect now
to see how this works see : https://www.elephantsql.com/docs/pgadmin.html
im more than happy to answer some questions
OK, this isn't really a solution but it might help you out. This happens to me on node 8 (and 10) but when I downgraded to node 7 it seems to work fine. I'll be watching this post to see if someone comes up with a better fix.

Error when trying to migrate tables created with seguelizeCLI

I got an error when try to migrate tables which are created using seguelizeCLI in node js,and when i change version of node js i also got different error message
1.this when i use stable node v9
TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be one of type string, TypedArray, or DataView
at Hash.update (internal/crypto/hash.js:53:11)
at sha1 (/home/dontito/NodeORMs/node_modules/mysql2/lib/auth_41.js:30:8)
at Object.token [as calculateToken] (/home/dontito/NodeORMs/node_modules/mysql2/lib/auth_41.js:64:16)
at new HandshakeResponse (/home/dontito/NodeORMs/node_modules/mysql2/lib/packets/handshake_response.js:28:24)
at ClientHandshake.sendCredentials (/home/dontito/NodeORMs/node_modules/mysql2/lib/commands/client_handshake.js:51:27)
at ClientHandshake.handshakeInit (/home/dontito/NodeORMs/node_modules/mysql2/lib/commands/client_handshake.js:142:10)
at ClientHandshake.Command.execute (/home/dontito/NodeORMs/node_modules/mysql2/lib/commands/command.js:40:20)
at Connection.handlePacket (/home/dontito/NodeORMs/node_modules/mysql2/lib/connection.js:502:28)
at PacketParser.onPacket (/home/dontito/NodeORMs/node_modules/mysql2/lib/connection.js:81:16)
at PacketParser.executeStart (/home/dontito/NodeORMs/node_modules/mysql2/lib/packet_parser.js:77:14)
at Socket.<anonymous> (/home/dontito/NodeORMs/node_modules/mysql2/lib/connection.js:89:29)
at Socket.emit (events.js:127:13)
at addChunk (_stream_readable.js:269:12)
at readableAddChunk (_stream_readable.js:256:11)
at Socket.Readable.push (_stream_readable.js:213:10)
at TCP.onread (net.js:590:20)
2.when i turn to other node version like v4
crypto.js:100
this._handle.update(data, encoding);
^
TypeError: Not a string or buffer
at TypeError (native)
at Hash.update (crypto.js:100:16)
at sha1 (/home/dontito/NodeORMs/node_modules/mysql2/lib/auth_41.js:30:8)
at Object.token [as calculateToken] (/home/dontito/NodeORMs/node_modules/mysql2/lib/auth_41.js:64:16)
at new HandshakeResponse (/home/dontito/NodeORMs/node_modules/mysql2/lib/packets/handshake_response.js:28:24)
at ClientHandshake.sendCredentials (/home/dontito/NodeORMs/node_modules/mysql2/lib/commands/client_handshake.js:51:27)
at ClientHandshake.handshakeInit (/home/dontito/NodeORMs/node_modules/mysql2/lib/commands/client_handshake.js:142:10)
at ClientHandshake.Command.execute (/home/dontito/NodeORMs/node_modules/mysql2/lib/commands/command.js:40:20)
at Connection.handlePacket (/home/dontito/NodeORMs/node_modules/mysql2/lib/connection.js:502:28)
at PacketParser.onPacket (/home/dontito/NodeORMs/node_modules/mysql2/lib/connection.js:81:16)
at PacketParser.executeStart (/home/dontito/NodeORMs/node_modules/mysql2/lib/packet_parser.js:77:14)
at Socket.<anonymous> (/home/dontito/NodeORMs/node_modules/mysql2/lib/connection.js:89:29)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
at TCP.onread (net.js:523:20)
You should change your password in config file like abc → "abc"

Scraping request run through Heroku Scheduler (Node.js) fails half the time

I set up a very basic web scraper to check stock of a specific item on Costco.com for my grandfather. It's working great locally, but when I run it through Heroku it fails (seemingly 50% of the time). Here's the code for the scraper
const task = () => {
// toggle so doesn't send message multiple times if continuously available
let alreadyAvailable = false;
let url = 'http://www.costco.com/Kirkland-Signature-Four-Piece-Urethane-Cover-Golf-Ball,-2-dozen.product.100310467.html';
request(url, function(error, response, html){
let $ = cheerio.load(html);
if(error){
throw new Error(error);
}
if ( $('#product-page #product-details #ctas #add-to-cart input[type="button"]')['0'].attribs.value === 'Out of Stock') {
alreadyAvailable = false;
console.log("still out of stock");
} else {
if (alreadyAvailable === false) {
sendMessage();
alreadyAvailable = true;
}
}
});
};
and here are the logs
2016-12-25T03:48:39.675549+00:00 heroku[scheduler.5440]: Starting process with command `node scraper.js`
2016-12-25T03:48:40.262503+00:00 heroku[scheduler.5440]: State changed from starting to up
2016-12-25T03:48:41.509416+00:00 app[scheduler.5440]: /app/scraper.js:34
2016-12-25T03:48:41.509432+00:00 app[scheduler.5440]: if ( $('#product-page #product-details #ctas #add-to-cart input[type="button"]')['0'].attribs.value === 'Out of Stock') {
2016-12-25T03:48:41.509433+00:00 app[scheduler.5440]: ^
2016-12-25T03:48:41.509433+00:00 app[scheduler.5440]:
2016-12-25T03:48:41.509434+00:00 app[scheduler.5440]: TypeError: Cannot read property 'attribs' of undefined
2016-12-25T03:48:41.509434+00:00 app[scheduler.5440]: at Request._callback (/app/scraper.js:34:90)
2016-12-25T03:48:41.509435+00:00 app[scheduler.5440]: at Request.self.callback (/app/node_modules/request/request.js:186:22)
2016-12-25T03:48:41.509436+00:00 app[scheduler.5440]: at emitTwo (events.js:106:13)
2016-12-25T03:48:41.509436+00:00 app[scheduler.5440]: at Request.emit (events.js:191:7)
2016-12-25T03:48:41.509436+00:00 app[scheduler.5440]: at Request.<anonymous> (/app/node_modules/request/request.js:1081:10)
2016-12-25T03:48:41.509437+00:00 app[scheduler.5440]: at emitOne (events.js:96:13)
2016-12-25T03:48:41.509437+00:00 app[scheduler.5440]: at Request.emit (events.js:188:7)
2016-12-25T03:48:41.509438+00:00 app[scheduler.5440]: at IncomingMessage.<anonymous> (/app/node_modules/request/request.js:1001:12)
2016-12-25T03:48:41.509438+00:00 app[scheduler.5440]: at IncomingMessage.g (events.js:291:16)
2016-12-25T03:48:41.509439+00:00 app[scheduler.5440]: at emitNone (events.js:91:20)
2016-12-25T03:48:41.509439+00:00 app[scheduler.5440]: at IncomingMessage.emit (events.js:185:7)
2016-12-25T03:48:41.509439+00:00 app[scheduler.5440]: at endReadableNT (_stream_readable.js:974:12)
2016-12-25T03:48:41.509440+00:00 app[scheduler.5440]: at _combinedTickCallback (internal/process/next_tick.js:74:11)
2016-12-25T03:48:41.509440+00:00 app[scheduler.5440]: at process._tickCallback (internal/process/next_tick.js:98:9)
2016-12-25T03:48:41.560539+00:00 heroku[scheduler.5440]: State changed from up to complete
2016-12-25T03:48:41.550655+00:00 heroku[scheduler.5440]: Process exited with status 1
2016-12-25T03:58:42.438807+00:00 app[api]: Starting process with command `node scraper.js` by user scheduler#addons.heroku.com
2016-12-25T03:58:43.701468+00:00 heroku[scheduler.5038]: Starting process with command `node scraper.js`
2016-12-25T03:58:44.312279+00:00 heroku[scheduler.5038]: State changed from starting to up
2016-12-25T03:58:45.769564+00:00 app[scheduler.5038]: still out of stock
2016-12-25T03:58:45.827867+00:00 heroku[scheduler.5038]: State changed from up to complete
2016-12-25T03:58:45.814921+00:00 heroku[scheduler.5038]: Process exited with status 0
You can see that sometimes I get the console log inside of the if-block and others I get a type error because it's trying to read attributes from an html element that don't exist. I was thinking that this might be a async issue, but I'm not sure how to go about fixing it. I assumed Request wasn't running the callback until it got all the html.
The problem here is what Costco's website is returning.
Your code is failing when parsing the DOM via Cheerio. What this means in your case is that the particular HTML you're attempting to scrape doesn't actually exist (that's what the error is saying).
This could be caused by a few possible things:
Costco is rendering a DIFFERENT page than what you expect (maybe it thinks you're a bot, or is doing some throttling).
You are receiving a redirect or some other sort of non-error HTTP status code, and the HTML you're looking for doesn't exist there.
Costco's website changes the HTML dynamically to prevent people from scraping.
What I would do if I were you is this:
Have your process log all the page's HTML when the task runs.
The next time your process fails, copy the HTML from the Heroku logs into a local editor, and see what it returned.
I'm willing to bet you will be surprised =)

Categories

Resources