Socket.io disconnects after certain time interval - node.js

We have created a real time chat application, with a socket.io, nodejs & mongodb. It is working fine on to a local & modulus server, but not working as expected on AWS.
Socket gets disconnected randomly with a ping timeout after around 60 sec. I also set "Heart Timeout" & "Heart Interval" but still it gets disconnected.
Here is the attached config file for node,
var config = {
local : {
mode : "LOCAL",
port : 8080,
db_path : "mongodb://localhost/local_db",
site_loc : "http://dummy.local/",
api_loc : "http://dummy.dummy.com/"
},
dev : {
mode : "DEV",
port : 8080,
db_path : "mongodb://dbath:27017/dev_db",
site_loc : 'http://dummy.dummy.com/',
api_loc : 'http://dummy.dummy.com/'
},
stage : {
mode : "STAGE",
port : 3000,
db_path : "mongodb://localhost:27017/stage_db",
site_loc : 'http://dummy.dummy.com/',
api_loc : 'http://dummy.dummy.com/'
},
production : {
mode : "PROD",
port : 443,
db_path : "mongodb://localhost:27017/live_db",
site_loc : 'https://dummy.com/',
api_loc : 'https://dummy.dummy.com/'
}
}
module.exports = function(mode) {
return config[mode || process.argv[2]] || config.local;
}

I resolved this issue, by just adding a port number besides link like,
http://www.chat.com:3000/
by d way thanks everyone...

Related

Mongodb - replica set - max connections

I have a replicaset of 3 mongo node, 1 primary, 1 secondary and 1 arbiter.
Connected on this replicaset, i have 20 node process, on 20 different serveur using their own connections to the replicaset. All those process use mongoose.
My primary replicaset show the following :
rsProd:PRIMARY> db.serverStatus().connections
{ "current" : 284, "available" : 50916, "totalCreated" : NumberLong(42655) }
From time to time, when i restart some nodejs node i have the following errors :
mongodb no valid seed servers in list
My connection string to the replicaset is the following :
"mongodb://mongo2aws.abcdef:27017/dbname,mongo1.abcdef:27017/dbname"
And my db options are the following :
config.db_options = {
user: "MYUSER",
pass: "MYPASSWORD",
replset: {
rs_name: "RSNAME",
ssl: true,
sslValidate:false,
sslCA: ca,
ca: ca,
sslKey: key,
sslCert: key
},
socketOptions : {
keepAlive : 1,
connectTimeoutMS : 1000
},
server: {
ssl: true,
sslValidate:false,
sslCA: ca,
ca: ca,
sslKey: key,
sslCert: key
},
auth: {
authdb: 'MYAUTHDB'
}
};
I haven't this error when i was running only 16 node process.
According to this i suppose that i have reach a limit of max concurrent connections or something like this.
But, if i restart again crashing node, it finally seems to work.
Why mongo / mongoose raise this error ?
What can i do to prevent this / increase limit ?
Thanks in advance
Best regards.
Solved by increasing ulimit open files
Default ulimit for open files in AWS EC2 ubuntu server is set to 1000 by default.
In addition, adding reconnect options prevent this problem :
config.db_options.reconnectTries=10;
config.db_options.reconnectInterval=500;
config.db_options.poolSize=20;
config.db_options.connectTimeoutMS=5000;

Logstash stopping {:plugin=>"LogStash::Inputs::Http"}

I'm trying to run Logstash in an EC2 Ubuntu instance,
but when I run:
logstash-5.2.0/bin/logstash -f logstash.conf --debug
I get:
Starting puma
Trying to start WebServer {:port=>9600}
start
Trying to start WebServer {:port=>9601}
[api-service] start
Successfully started Logstash API endpoint {:port=>9601}
PeriodicPoller: Stopping
stopping pipeline {:id=>"main"}
Closing inputs
stopping {:plugin=>"LogStash::Inputs::Http"}
Closed inputs
This is logstash.conf
input
{
http
{
host => "127.0.0.1"
port => 31311
}
}
output
{
elasticsearch
{
hosts => ["localhost:9200"]
}
stdout
{
codec => rubydebug
}
}
When I run
curl 'http://localhost:9200/?pretty'
I get:
{
"name" : "QrRfI_U",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "LLdvAaAsQSCULTfl_b4xIA",
"version" : {
"number" : "5.2.0",
"build_hash" : "24e05b9",
"build_date" : "2017-01-24T19:52:35.800Z",
"build_snapshot" : false,
"lucene_version" : "6.4.0"
},
"tagline" : "You Know, for Search"
}
So elasticsearch is running fine.
What if you have your hosts as:
hosts => "localhost"
And make sure that the http port which you've mentioned above is not bound to any other process.
If that's not the case just to make sure, run plugin list and check whether http-input plugin does exist.

Basic test fails on nightwatch phantomjs browser

I am using selenium server, nightwatch on node.js and phantomjs for selenium. I use phantomjs just for headless browser (with it selenium doesn't open browser visually when running tests).
My basic test passes when I use firefox as the browser but fails when I use phantomjs browser.
I setup basic google test:
module.exports = {
'Demo test Google' : function (browser) {
browser
.url('http://www.google.com')
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'nightwatch')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.pause(1000)
.assert.containsText('#main', 'Night Watch')
.end();
}
};
And setup phantomjs server. This is my nightwatch.json:
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : false,
"server_path" : "selenium-server-standalone-2.53.1.jar",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 3001,
"cli_args" : {
"webdriver.chrome.driver" : "",
"webdriver.ie.driver" : ""
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_port" : 3001,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : false,
"path" : ""
},
"desiredCapabilities": {
"browserName": "phantomjs",
"javascriptEnabled": true,
"acceptSslCerts": true,
"phantomjs.binary.path" : "phantomjs.exe"
}
}
}
}
When I set browserName to "firefox", test passes, "OK. 3 assertions passed.".
But when it is "phantomjs", one passes, one fails, and one error during execution: " TEST FAILURE: 1 error during execution, 1 assertions failed, 1 passed. (3.511s)".
With errors:
Timed out while waiting for element to be present for 1000 milliseconds. - expected "visible" but got: "not found"
ERROR: Unable to locate element: "input[type=text]" using: css selector
I start server manually.
I tested with latest version of phantomjs (2.1.1) and with 1.9.8
EDIT:
Selenium server also reports this error when using phantomjs:
WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP.
I encoutnered something like this in the past and observed that Default size of phantomjs browser was very small. Could you please try resizing browser and check what happens.
Something like below,
module.exports = {
'Demo test Google' : function (browser) {
browser
.url('http://www.google.com')
.resizeWindow(1000, 800);
.waitForElementVisible('body', 1000)
.setValue('input[type=text]', 'nightwatch')
.waitForElementVisible('button[name=btnG]', 1000)
.click('button[name=btnG]')
.pause(1000)
.assert.containsText('#main', 'Night Watch')
.end();
}
};
Yes, resizing the browser window may solve this problem. We are running our test suite in Phantom JS and we have set this in code when we initialize the browser window:
client.maximizeWindow();

Nightwatch.js won't get URL on server OS

I have a test that works fine on my machine, but I'm running into problems when I try to move it to the server OS (Windows Server 2008 specifically). All the test really needs to do is load up each URL from a file. When I run it on the server os, it only loads a blank page. But I know it's reading the file, because I can console.log out the list of URLs, and also if my file has 5 lines, it will say 5 tests failed.
A different test I tried which doesn't read from a file, which is just given an array of a few URLs to read through works fine, by the way
Any idea what's going on? Here is my code:
var fs = require('fs');
var i = 0;
var errorlog = "";
module.exports = {
'Person Page Test w/ txt file' : function (browser) {
//iterates through excel sheet testing each URL
fs.readFileSync('PersonPageUrls.txt').toString().split('\n').forEach(function (line) {
var url = line;
i++;
console.log(url);
browser
.url(url)
.saveScreenshot('tests/PersonPage/screenshots/PersonPage' + i + '.png')
.waitForElementVisible('button[class=Person__readMoreButton___28toI]', 3000, false, function(result) {
if (!result.value) {
//if test fails, add to error log string
browser.url(function(currentUrl){
console.log();
errorlog = errorlog + "Test fail on: " + currentUrl.value + "\r\n";
});
}
});
});
browser.end()
}
};
and my nightwatch.json
{
"src_folders" : ["tests"],
"output_folder" : "reports",
"custom_commands_path" : "",
"custom_assertions_path" : "",
"page_objects_path" : "",
"globals_path" : "",
"selenium" : {
"start_process" : true,
"server_path" : "selenium-server-standalone-2.48.2.jar",
"log_path" : "",
"host" : "127.0.0.1",
"port" : 4444,
"cli_args" : {
"webdriver.chrome.driver" : "",
"webdriver.ie.driver" : ""
}
},
"test_settings" : {
"default" : {
"launch_url" : "http://localhost",
"selenium_port" : 4444,
"selenium_host" : "localhost",
"silent": true,
"screenshots" : {
"enabled" : true,
"on_failure" : true,
"on_error" : true,
"on_success" : true,
"path" : ""
},
"desiredCapabilities": {
"browserName": "firefox",
"javascriptEnabled": true,
"acceptSslCerts": true
}
},
"chrome" : {
"desiredCapabilities": {
"browserName": "firefox",
"javascriptEnabled": true,
"acceptSslCerts": true
}
}
}
}
Heres the output I get (running on a 2 line text file) (if it isn't obvious, I replaced the real URLs it prints with ~~~~. But it does print the urls):
D:\NightwatchProjects>nightwatch -t tests/PersonPage/personpagetxt.js
Starting selenium server... started - PID: 3004
[Person Page\personpagetxt] Test Suite
======================================
Running: Person Page Test w/ txt file
~~my url 1 ~~
~~my url 2~~
? Timed out while waiting for element <button[class=Person__readMoreButton___28
toI]> to be present for 3000 milliseconds. - expected "visible" but got: not fo
und
at D:\NightwatchProjects\tests\PersonPage\personpagetxt.js:26:8
at Array.forEach (native)
at Object.module.exports.Person Page Test w/ txt file (D:\NightwatchProjects
\tests\PersonPage\personpagetxt.js:18:66)
at Module.call (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch
\lib\runner\module.js:63:34)
at C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\lib\runner\t
estcase.js:97:29
at _fulfilled (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\
node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\Users\me\AppData\Roaming\npm\node_modu
les\nightwatch\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\Users\me\AppData\Roaming\npm\nod
e_modules\nightwatch\node_modules\q\q.js:796:13)
at C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\node_modules
\q\q.js:556:49
at runSingle (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\n
ode_modules\q\q.js:137:13)
? Timed out while waiting for element <button[class=Person__readMoreButton___28
toI]> to be present for 3000 milliseconds. - expected "visible" but got: not fo
und
at D:\NightwatchProjects\tests\PersonPage\personpagetxt.js:26:8
at Array.forEach (native)
at Object.module.exports.Person Page Test w/ txt file (D:\NightwatchProjects
\tests\PersonPage\personpagetxt.js:18:66)
at Module.call (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch
\lib\runner\module.js:63:34)
at C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\lib\runner\t
estcase.js:97:29
at _fulfilled (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\
node_modules\q\q.js:834:54)
at self.promiseDispatch.done (C:\Users\me\AppData\Roaming\npm\node_modu
les\nightwatch\node_modules\q\q.js:863:30)
at Promise.promise.promiseDispatch (C:\Users\me\AppData\Roaming\npm\nod
e_modules\nightwatch\node_modules\q\q.js:796:13)
at C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\node_modules
\q\q.js:556:49
at runSingle (C:\Users\me\AppData\Roaming\npm\node_modules\nightwatch\n
ode_modules\q\q.js:137:13)
FAILED: 2 assertions failed (11.389s)
Test fail on: about:blank
Test fail on: about:blank
----------------------------------------------------
TEST FAILURE: 2 assertions failed, 0 passed (11.53s)
? PersonPage\personpagetxt
- Person Page Test w/ txt file
Timed out while waiting for element <button[class=Person__readMoreButton___
28toI]> to be present for 3000 milliseconds. - Expected "visible" but got: "not
found"
Timed out while waiting for element <button[class=Person__readMoreButton___
28toI]> to be present for 3000 milliseconds. - Expected "visible" but got: "not
found"
D:\NightwatchProjects>

Unable to execute nightwatch tests on chrome using Linux

Here's the bit in question from my nightwatch.json file :
"selenium" : {
"start_process" : true,
"server_path" : "lib/selenium-server-standalone.jar",
"log_path" : "test_logs"
},
"test_settings" : {
"jenkins" : {
"launch_url" : "url not disclosed",
"selenium_port" : 4444,
"selenium_host" : "jenkins.undisclosed-cloud.com",
"cli_args" : {
"webdriver.chrome.driver" : "/usr/local/bin/chromedriver"
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": true,
"platform" : "LINUX"
}
}
}
If I change the browserName to firefox then the test runs fine in the specified linux server, which is running on a DOCKER CONTAINER.
But when i choose chrome, i am getting the error:
Connection refused! Is selenium server started?
I've seen this error before on my local machine and managed to fix it by adding chromedriver to the path. I thought it would be the same issue on this linux server but it did not resolve it. I went on to the linux box and verified I can start the chromedriver directly in
"/usr/local/bin/chromedriver"
By the way I have verified I'm on 64-bit linux machine and the symlinks are all set.
Linux version: Linux 3.11.0-26-generic | v2.43.1 | r5163bce
ERROR LOG AFTER RUNNING TEST WITH --verbose
INFO Request: POST /wd/hub/session
- data: {"desiredCapabilities": {"browserName":"chrome","javascriptEnabled":true,"acceptSslCerts":true,"platform": "LINUX","name":"Free Resource Download Test"}}
- headers: {"Content-Type":"application/json; charset=utf-8","Content- Length":151}
ERROR Response 500 POST /wd/hub/session{ status: 13,
sessionId: null,
value:
{ message: 'chrome not reachable\n
So, this is a docker container and a problem is within Chrome&Docker.
you have 2 options, either run add "--privileged" parameter to a Docker or run Chrome with "--no-sandbox" argument.

Resources