   for message in messages
     if message.user_id of listeners
       # Respond to the listener
-      listeners[message.user_id].send message.data
+      for res in listeners[message.user_id]
+        try
+          res.send message.data
+        catch
+          # Dead listener, just ignore it
       closed[message.user_id] = true
       delete listeners[message.user_id]
     else if message.user_id of closed

  , constants.NOTIFICATION_LOOP_TIMEOUT

exports.get_notifications = (req, res) ->
  # If it was already in listeners, close the old one
  if req.user.id of listeners
    try
      listeners[req.user.id].send({status: 'ok', error: 'closed'})
    catch err
    # Probably navigated away or something
      console.log err
  # Put the response object in our listeners map
  listeners[req.user.id] = res

send_notification = (user_id, data) ->
  messages.push {user_id, data}

  msg = 'You have a new message. <a href="' + link + '"">Click here to view</a>!'
  api_controller.render_flash 'info', msg, (err, html) ->
    data = {
      status: 'ok'
      message: html
    }
    send_notification user_id, data
