I have a Next js application which make requests to commerce js api, from getStaticProps function. I've tried to make the build several times, and sometimes it goes well, but sometimes it fails giving me the following error.
Error: timeout of 10000000ms exceeded at createError (/Users/nicolo/Desktop/shop-smb-for-schools/shop-smb-template-commercejs/node_modules/axios/lib/core/createError.js:16:15) at RedirectableRequest.handleRequestTimeout (/Users/nicolo/Desktop/shop-smb-for-schools/shop-smb-template-commercejs/node_modules/axios/lib/adapters/http.js:280:16) at Object.onceWrapper (node:events:627:26) at RedirectableRequest.emit (node:events:512:28) at eventHandlers.<computed> (/Users/nicolo/Desktop/shop-smb-for-schools/shop-smb-template-commercejs/node_modules/follow-redirects/index.js:13:24) at ClientRequest.emit (node:events:512:28) at TLSSocket.emitRequestTimeout (node:_http_client:841:9) at Object.onceWrapper (node:events:626:28) at TLSSocket.emit (node:events:524:35) at Socket._onTimeout (node:net:564:8)
I've tried to change the milliseconds settings from the config object when creating the instance of Commercejs, and even if the time is not expired it raises the error. Instead, if I try making the requests to the api, client side, they work properly even if they take some time.
Related
I'm using node.js to post JSON records to an API that stores the records in a database.
There can be lots of records (lets say 100.000), and to avoid too big requests (to long response times), I send 2500 records per request to the API.
Despite of this, I randomly can receive the following error:
events.js:167
throw er; // Unhandled 'error' event
^
Error: socket hang up
at createHangUpError (_http_client.js:322:15)
at Socket.socketOnEnd (_http_client.js:425:23)
at Socket.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1092:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
Emitted 'error' event at:
at Socket.socketOnEnd (_http_client.js:425:9)
at Socket.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1092:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
My API works very hard when this import takes place. I'm not only inserting the records. I'm also doing some verification checks before insert. I guess the reason is because the request gets timeout.
My first thought was to add handling of this exception, and doing retry of the request if it fails.
I've tried to add handling of the exception by adding a try/catch clause around the request code. This does not catch the exception.
Normally an unhandled exception shows reference to were in my code the exception I triggered from. In this case, based on the error message, its only reference to language classes/modules.
The question is: Where should I add handling of this exception?
This error randomly appears When leaving my discord bot online for too long, around 3-4 hours but sometimes the error occurs sooner and sometimes later. It's really bothering me.
events.js:188
throw err;
^
Error: Unhandled "error" event. ([object Object])
at Client.emit (events.js:186:19)
at WebSocketConnection.onError (D:\BasementMonster\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:374:17)
at WebSocket.onError (D:\BasementMonster\node_modules\ws\lib\event-target.js:128:16)
at emitOne (events.js:116:13)
at WebSocket.emit (events.js:211:7)
at _receiver.cleanup (D:\BasementMonster\node_modules\ws\lib\websocket.js:211:14)
at Receiver.cleanup (D:\BasementMonster\node_modules\ws\lib\receiver.js:557:13)
at WebSocket.finalize (D:\BasementMonster\node_modules\ws\lib\websocket.js:206:20)
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)
I wrestled with this problem for a while in my own code. The main problem is that the trace is completely unhelpful, and that the error occurs so infrequently as to make "run it in the terminal and wait" a futile task. Eventually, I was able to figure out that the Discord.js client itself was throwing an error -- this wasn't mentioned in any of the documentation I read, so I had no handler for it -- and since this oopsie happens in the Discord.js package itself, there was no line in my code for it to point to in the trace.
What needs to exist in the code somewhere is something along the lines of
client.on('error', (err) => {
console.log(err.message)
});
This is adjusted, of course, for whatever your Client object is, and whatever you want the error handling to be.
This specific trace, as far as I can tell, comes from losing Internet connection, which is something I want to have a record of, so instead of console.log() I called my own custom function that writes the event out to a logfile with a timestamp.
Testing this by running an instance of the bot and killing my Internet connection revealed that not only did the logging function work, but that Discord.js automatically restored the bot's session after it came back. (Your mileage may vary.)
You need to add an error handling event, like this:client.on('error', console.error);
I am using Requests js to make http requests. My script makes a GET request every 1 minute to an url that is secured over SSL. For 3 hour, everything works totally ( It made over 150 requests successfully). Suddenly, my node js app crashed and printed this error:
SSL routines:SSL3_GET_RECORD:decryption failed or bad record mac:s3_pkt.c:535
at _errnoException (util.js:1022:11)
at WriteWrap.afterWrite [as oncomplete] (net.js:880:14) code: 'EPROTO', errno: 'EPROTO', syscall: 'write' }
The error stack trace pointed me to an error in request js result.
What does the above error mean? How to catch it and prevent it to happen again in the future?
I've read all the related issues on SO and GitHub about this error and none of them seem to address this situation.
When I run the following code:
response = await axios.get('http://localhost:8082/panda, {
httpAgent: new http.Agent({ keepAlive: true, keepAliveMsecs: 10000 })
});
I get the following error:
{ Error: socket hang up
at createHangUpError (_http_client.js:345:15)
at Socket.socketOnEnd (_http_client.js:437:23)
at emitNone (events.js:110:20)
at Socket.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1059:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9) code: 'ECONNRESET' }
{ Error: read ECONNRESET
at _errnoException (util.js:1019:11)
at TCP.onread (net.js:608:25)
code: 'ECONNRESET',
errno: 'ECONNRESET',
syscall: 'read',
etc...
There's no stack trace beyond the onread call so it's unclear how I can get any additional information beyond the ECONNRESET error code (-54) passed to the onread method in net.js
This issue happens with every request - it is not intermittent.
A few observations:
when making the same request from chrome or postman the request does NOT fail
attempting to reproduce a successful request from Chrome, by using the same headers, fails
setting the accept header to use 'gzip', etc.. does not help - I have tried all the recommendations including some weird ones like setting the content length and adding a body to the request despite this being a GET request
the error always appears in net.js, but happens with both the request and axios libraries
Here's the interesting part - I can only seem to reproduce this problem reliably when I am hosting the server locally. I am able to reach the dev instance or run the server in vagrant, via a docker container, without issue.
I am running macOS Sierra 10.12.6 if that makes any difference. The server is written in Java and uses the Spring framework. Here is the RestTemplate configuration I'm using for HTTP calls:
#Bean
public RestTemplate restTemplate() {
//request timeout
int timeout = 5000;
//Connection Pooling factory with timeouts to prevent disastrous request responses
HttpComponentsClientHttpRequestFactory cf = new HttpComponentsClientHttpRequestFactory();
cf.setReadTimeout(timeout);
cf.setConnectTimeout(timeout);
cf.setConnectionRequestTimeout(timeout);
return new RestTemplate(cf);
}
I've tried messing around with these settings with no luck.
Any ideas?
I have the same issue. The cause was in my proxy settings. I make proxy-port localhost:8080 to my localhost:3000. That's why all API requests from my NodeJS app to localhost:3000 returned "ECONNRESET" Error. When I delete proxy-port, the issue was resolved. Check your net settings. Maybe it's redirecting problem
This was a known issue with NodeJS and has been resolved. Please see http.Agent: idle sockets throw unhandled ECONNRESET for details.
Also ensure you have enabled the correct security settings when opening a port on MacOS
This bug has been crashing my node.js server for the past one week. On average it seems to occur every 12 hours. Normally when an error occurs in node.js, node.js will tell you the line number and your source file that lead to the error. However, this error is so weird that it does not let me know where the error originates from in my source codes. I can't even find _http_server.js within the entire project and node modules. As such, I have been unable to pinpoint and eliminate the bug.
Without the stack trace module 'longjohn', I would get the following error message:
socket.parser.resume()
cannot read property resume of null (_http_server.js:442)
......
After I installed 'longjohn', I obtained the following error message:
TypeError: Cannot read property 'resume' of null
at socketOnDrain (_http_server.js:442:20)
at ServerResponse.updateOutgoingData [as _onPendingData] (_http_server.js:270:14)
at ServerResponse.OutgoingMessage._send (_http_outgoing.js:128:14)
at ServerResponse.OutgoingMessage.write (_http_outgoing.js:470:16)
at ReadStream.ondata (_stream_readable.js:525:20)
at emitOne (events.js:77:13)
at ReadStream.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at ReadStream.Readable.push (_stream_readable.js:110:10)
at onread (fs.js:1744:12)
at FSReqWrap.wrapper [as oncomplete] (fs.js:576:17)
---------------------------------------------
at ReadStream.Readable.on (_stream_readable.js:655:33)
at ReadStream.Readable.pipe (_stream_readable.js:522:7)
at SendStream.stream (C:\XXXX\node_modules\express\node_modules\send\lib\send.js:533:10)
at SendStream.send (C:\XXXX\node_modules\express\node_modules\send\lib\send.js:480:8)
at C:\XXXX\node_modules\express\node_modules\send\lib\send.js:392:10
at FSReqWrap.oncomplete (fs.js:82:15)
worker 1760 died
It is worthwhile mentioning that I am using socket.io. I am also using an external service called Global Counter that displays the number of online users. I am running setInterval() in one of the workers to remove expired records.
Could someone tell me the meaning of these error messages, how the error occurs, and how I should solve it?
according to https://github.com/nodejs/node/issues/3508, you may fix this problem after upgrading nodejs to v4.2.3+ or v5.1.1+