node.js - MongoDB: Waiting for available socket hanging -


so using mongoose's findoneandupdate update key value in document. needing increment number one. if it's not in there should create new document. it's in post route in node.

i have information going post route on button click. app requires users click button multiple times in succession , i'm getting waiting available sockets... @ bottom of browser , hangs.

i doing on localhost. @ end of request once "unhangs" following error in console: post http://localhost:3000/api/songsqueued net::err_empty_response

this post route i'm working with:

router.post('/api/songsqueued', function(req, res){     song.findoneandupdate({songid: req.body.songid}, { $inc:{queuetimes: 1} },         function(err, song){         if (err) {             return console.log("error: " + err)         }         if(song){             song.queuetimes += 1;              song.save(function(err){                 if(err){                     console.log(err)                 } else {                     console.log("updated fam")                 }             });         } else {              var song = new song();              song.artistname = req.body.artistname;             song.titlename = req.body.titlename;             song.songid = req.body.songid;             song.songimg = req.body.songimg;               song.save(function(err) {               if (err) {                 console.log("error: " + err)               } else {                 console.log("created fam")               }             })              console.log(song);             return res.json({message: "songcreated"})          }      }) }) 

any ideas on how remedy this?

your node server needs send response client in order response complete. if don't send response, connection timeout , socket hangup. make sure send response each condition:

if (err) {   return res.status(500).end("some error message"); } else if (song) {   return res.status(200).end("updated"); } else {   return res.status(201).end("created"); } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -