neo4j-javascript-driver icon indicating copy to clipboard operation
neo4j-javascript-driver copied to clipboard

Running an array of cypher queries with Promise.all hangs

Open sureshrajan8 opened this issue 5 years ago • 1 comments
trafficstars

I have created a service to run Cypher query and hen I call this service in an array to Promise.all. Promise.all works efficiently until 6 sets of queries but as it exceeds it hangs. No response!

Service query looks like this:

async function run(queryObj){
    try{        
        var session=db.session();
        const txc = session.beginTransaction();
        try{          
            queryObj.params=convert.NumToint(queryObj.params);
            let result= await txc.run(queryObj.query,queryObj.params);
            let status=await txc.commit();
            let data=[];
            result.records.forEach(record=>{
                let element={};
                let len=record.length;
                let keys=record.keys;
                for(let i=0;i<len;i++){
                    element[keys[i]]=record.get(keys[i]);    
                }
                data.push(convert.Map(element));
            })
            return data;
        } catch(err){
            await txc.rollback();
            throw err;
        } finally {
            await session.close();
        }
    } catch(err){
        console.log(err);
        throw err;
    }
}

sureshrajan8 avatar May 06 '20 17:05 sureshrajan8

@sureshrajan8 This looks like you are committing the transaction before consuming the query result inside it. You should refactor your code to consume the result first, before committing.

technige avatar Jun 10 '20 09:06 technige

Closed due long inactive. This issue could be re-opened if needed.

bigmontz avatar Sep 15 '22 13:09 bigmontz