Nodejs and Sphinx data query issue - node.js

I have been using limestone module and Nodejs to query sphinx index. The limestone is out-dated in my npm so i downloaded from github and it is got connected to the sphinx server successfully. But i am now facing the issue as follows,
When i tried to execute the following code,
var limestone = require("limestone").SphinxClient(),
sys = require("sys");
limestone.connect("192.168.2.443:9312", // port. 9312 is standard Sphinx port. also 'host:port' allowed
function(err) {
if (err) {
sys.puts('Connection error: ' + err);
}
sys.puts('Connected, sending query');
limestone.query(
{'query':'raja',maxmatches:1},
function(err, answer) {
if(err){
console.log("Sphinx ERR: "+err);
}else{
console.log(JSON.stringify(answer));
limestone.disconnect();
}
});
});
i got the below error,
Sphinx ERR: Searchd command older than client's version, some options might not workServer issued ERROR: 0bad multi-query count 0 (must be in 1..32 range)
Please help me on this!

Ok, so I installed sphinxseach on Ubuntu, the version in the repository is 0.9.9. I got a similar error as yours:
Searchd command older than client's version, some options might not workServer issued ERROR: Qclient version is higher than daemon version (client is v.1.24, daemon is v.1.22) undefined
After looking through the issues at limestone's github, I figured it was supposed to work with Sphinx version 2. So I installed 2.0.4 from Sphinx download page (they have Ubuntu packages), and it works! So, if it's possible for you to upgrade, that might be a good idea anyway -- and limestone will probably only ever track the latest release.

Related

Firebase functions throws uncatchable error

I'm calling the following Firebase function:
exports.getUserRecord = functions.https.onCall(async (data, context) => {
try {
//This successfully logs an existing uid in firestore, it should be retrievable
console.log(context.auth.uid)
const doc = admin.firestore().collection('user').doc(context.auth.uid);
const res = await doc.get() //Isolated it down to this line that is failing
return res
} catch (err) {
console.log(err)
throw new functions.https.HttpsError('unavailable', 'some error message');
}
});
When calling this function I receive the following error on the client:
POST https://us-central1-xxx-xxx.cloudfunctions.net/getUserRecord 500
Uncaught (in promise) Error: INTERNAL
On the server logs I see this error:
Unhandled error function error(...args) {
write(entryFromArgs('ERROR', args));
}
I am wondering how there is an error that neither of my error logging lines are picking up, and also what is causing this error?
EDIT: I have also tried logging other things within my catch block but they do not appear, it seems there is an error but the code does not enter the catch block somehow.
I have also seen this post which seems to suggest this was an issue that was patched in firebase-functions 3.9.1, but I have upgraded and still have this issue
Walked through the firebase-functions code for onCall at v3.11.0 and I don't see any other issues that could relate to this in the code since the fix
https://github.com/firebase/firebase-functions/issues/757
After discussing with #Matt about node_module versions we found that the issue is related to node_modules not having updated to latest once the upgrade was initially done.
Notes for anyone running into this issue in the future
If updating to latest for this module make sure to do the following to cover all bases,
Look into node_modules/firebase-functions/package.json attribute version to make sure that the proper version is installed.
Also take a look at your root folder package.json and package-lock.json to makes sure the proper versions are the latest.
If anything is not at version v3.9.1 or higher, then do the following,
rm -rf node_modules
npm i firebase-functions#latest --save
After that, double check everything again to make sure all is good.

Postgres database does not connect, .sync() does not resolve. Sequelize, PostgreSQL, Node

Recently, I got a new laptop and I am set up my development environment on there. Also, I copied a project I worked on on my old laptop and wanted to continue working on it on my new laptop. Nothing weird here, I would think. The server-side code in this case.
So I started with installing all the apps and programs, cloned my GitHub repo, booted up a docker container with the following command:
docker run -d -p 5432:5432 --name ulti-mate -e POSTGRES_PASSWORD=secret postgres
and ran npm install. I connected to the database using postico, just to have a little visual feedback, which connected instantly. Then started the server up using nodemon index.js and it seemed to start. Only I was missing one thing: Normally the server console logs Database connected and runs a bunch of insert queries. Went to Postico, nothing.
I've been going over the code of my database:
const Sequelize = require('sequelize');
const databaseUrl =
process.env.DATABASE_URL ||
'postgres://postgres:secret#localhost:5432/postgres';
const db = new Sequelize(databaseUrl);
async function syncDB() {
try {
console.log('Before sync');
await db.sync({ force: false });
console.log('Database connected');
} catch (error) {
console.error('error synching database', error);
}
}
syncDB();
and I noticed that it runs until it hits db.sync(). Before sync logs consistently. That's where it stops. It doesn't resolve at all. I tried assigning it to a variable, but nothing. For example, this does not log:
const a = await db.sync({force: false});
console.log("a:", a);
The weird thing is that it worked before on my old machine, so the problem can't be in the code. It must have something to do with my new development environment. I tried installing different versions of sequelize and pg in the repo, didn't help. I tried reinstalling postgresql with homebrew, but it's up to date.
If anyone has an idea what might be going wrong or something I might try to fix this issue, it would be greatly appreciated, because I'm slowly going mad.
I figured out the problem. I was running Node v14.4.0 (latest version at the moment). Downgrading to the latest LTS version (v12.18.1) fixed the issue. I'm not sure if this is a known issue, but I opened a ticket on the sequelize Repo.

How do I get a response/information from a hanging pgPool.connect()?

I am using the pg package (node.js), and for some reason the connect function gives me nothing. My code gets hung up on that line and I'm unable to see any errors, what's wrong, or what's happening.
i.e.
console.log("HERE");
await pgPool.connect()
console.log("NOW HERE") //this line never prints
I've tried a bunch of variations too:
console.log("HERE");
const client = await pgPool.connect()
console.log(client) //this line never prints
Does anyone know how to get a verbose stream from pg? My pg version is 7.15.0 and my npm version is 6.14.4
I've tried waiting it out for over an hour. For friends running the same code from the same branch on their local machines it connects in under a second. I've confirmed they have the same version of pg as me.
I am able to connect directly to the database using psql in a separate terminal without issues (it immediately connects in < 1 second)
Updated my pg to 8.2.1 and it solved the problem. Must be an incompatibility issue with an earlier version

Nodejs, moch/chai failing with "Segmentation fault: 11" on macOS

I am running mocha/chai (3.2.0/3.5.0) based test cases for my nodejs (6.10.2) based application, on macOS 10.12.4, and I am running into a "Segmentation fault: 11" failure.
So far I have tried:
Erasing my node_modules folder and doing a new npm install
Checking for outdated dependencies and upgrading them
Upgrading the nodejs version (was using 6.7.0), via sudo port upgrade nodejs6
The code that is failing for me is as follows.
chai.request(url)
.post(`/api/filestore?token=${token}`)
.timeout(20000)
.attach('file', fs.readFileSync(filepath), filename)
.field('name', data.name)
.field('description', data.description)
.field('keywords', data.keywords)
.end(function(err, res) {
if (err) { done(err); }
res.should.have.status(200);
res.should.be.json;
res.body.should.have.property('name');
res.body.should.have.property('description');
res.body.should.have.property('categories');
res.body.keywords.should.be.a('array');
res.body.keywords.join(',').should.be.equal(data.keywords);
done();
});
The segmentation fault disappears when I remove the 'attach' line:
.attach('file', fs.readFileSync(filepath), filename)
I have tried the fs.readFileSync(filepath) separately and I don't encounter the issue.
This wasn't an issue in the past and only became an issue recently. I am wondering whether it coincides with the upgrade of the OS, but I can't be sure. Test file is only 34K in size.
Does anyone have any suggestions?
Edit: Failing on Ubuntu test machine as well with a segmentation fault.
It seems like the chai code was a 'red herring'. Using the segfault-handler node module, I was able to establish that the issue was actually being caused by code in the project being tested (it is running in the same process).
In my case, the stack trace suggested the issue was being caused by something in the sqlite3 code. Further investigation revealed it was due to not handling the return value of in the function passed to Promise.mapSeries, which was doing a sqlite SQL operation, via Sequelize.
Note I am using bluebird for my promises.

node js mongodb remove error "key $lte must not start with '$'"

db.collection('session').remove({timestamp:{'$lte':a}},function(err, docs) {
console.log(err)
console.log(docs)
});
Version mongodb is 2.6.5, when I make this query from Robomongo visual manager it works normally but from node js it throws error "key $lte must not start with '$'"
I also faced similar issue with some downloaded code- shell worked properly but Node driver failed (there was no other external library like mongoose). My installed MongoDB version was 2.6.6 and the package.json had a mongodb entry as "~1.3.18". With a suggestion from someone, I changed the entry value to "~1.4.31" which resolved my problem.
Remove the quotes around $lte. It is not a key, but a directive.

Resources