title: Last callback not being called using async
body: <p>I cannot seem to get the last callback (commented as "optional callback") called to send the result back to the browser. Any pointers as to what I am doing wrong? I am using the following modules: async, restify and postgresql for node.js</p>
  
  <pre><code>console.log('Start');
  
  var async = require('async');
  var restify = require('restify');
  var server = restify.createServer();
  server.use(restify.bodyParser());
  
  server.get('/user/creationdate/:username', function(req, res, next) {
      var userName = req.params.username;
      var record;
  
      async.parallel([
          function(callback){
              getUserByName(userName, function(err, user) {
                  if (err) return callback(err);
                  record = user;
              });
          }
      ],
  // optional callback
          function(err){
              console.log('5. Following record has been retrieved:' + record);
              res.send(record);
          });
  
      next();
  });
  
  server.listen(8080, function () {
      console.log('%s listening at %s', server.name, server.url);
  });
  
  handleError = function handleError(err) {
      if(!err) { return false; }
      else {
          console.log('The following error occurred:' + err);
  
      }
      return true;
  };
  
  function getPgClient(){
      var pg = require('pg');
  
      var client = new pg.Client({
          user: 'postgres',
          password: 'password',
          database: 'foobar',
          host: '192.168.1.100',
          port: 5432
      });
  
      client.on('drain', client.end.bind(client)); //disconnect client when all queries are finished
  
      return client;
  }
  
  function getUserByName(userName, callback){
      var client = getPgClient();
      console.log('2. Trying to connect to DB');
  
      client.connect(function(err) {
          console.log('3. Error connecting to DB:' + handleError(err));
          if(handleError(err)) return callback(err);
  
          client.query("SELECT created_at FROM users WHERE username='" + userName + "'", function(err, result) {
              if(handleError(err)) return;
              console.log('4. Error occurred:' + err);
              console.log(result);
              console.log(callback);
              callback(null, result);
          })
      });
  }
  </code></pre>