{"action":"closed","issue":{"url":"https://api.github.com/repos/node-xmpp/node-xmpp-server/issues/100","labels_url":"https://api.github.com/repos/node-xmpp/node-xmpp-server/issues/100/labels{/name}","comments_url":"https://api.github.com/repos/node-xmpp/node-xmpp-server/issues/100/comments","events_url":"https://api.github.com/repos/node-xmpp/node-xmpp-server/issues/100/events","html_url":"https://github.com/node-xmpp/node-xmpp-server/issues/100","id":75592861,"number":100,"title":"BOSH client doesn't always emit close event","user":{"login":"sonnyp","id":19673,"avatar_url":"https://avatars.githubusercontent.com/u/19673?v=3","gravatar_id":"","url":"https://api.github.com/users/sonnyp","html_url":"https://github.com/sonnyp","followers_url":"https://api.github.com/users/sonnyp/followers","following_url":"https://api.github.com/users/sonnyp/following{/other_user}","gists_url":"https://api.github.com/users/sonnyp/gists{/gist_id}","starred_url":"https://api.github.com/users/sonnyp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sonnyp/subscriptions","organizations_url":"https://api.github.com/users/sonnyp/orgs","repos_url":"https://api.github.com/users/sonnyp/repos","events_url":"https://api.github.com/users/sonnyp/events{/privacy}","received_events_url":"https://api.github.com/users/sonnyp/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-12T12:54:57Z","updated_at":"2015-08-10T10:25:37Z","closed_at":"2015-08-10T10:25:37Z","body":"The issue is that when sending data to the BOSH client 'while' the BOSH client disconnected will block node from emitting the close event on the request which prevents node-xmpp-server emitting the close event on the BOSHSession/C2SStream objects.\r\n\r\nLooks like a node issue. Maybe related https://github.com/iojs/io.js/issues/1309\r\n\r\nHere is the workaround: https://github.com/node-xmpp/node-xmpp-server/pull/101\r\n\r\n# Test case\r\n\r\n(Node.js 0.12.2)\r\n\r\n### Server\r\n```javascript\r\n'use strict';\r\n\r\nvar Server = require('node-xmpp-server').BOSHServer;\r\nvar Stanza = require('node-xmpp-core').Stanza.Stanza;\r\n\r\nvar server = new Server({\r\n  port: '5281',\r\n  autostart: true\r\n});\r\n\r\nvar f;\r\n\r\nserver.on('connect', function(client) {\r\n  console.log('server connection');\r\n  client.once('authenticate', function(opts, cb) {\r\n    cb(null, opts);\r\n  });\r\n  client.once('online', function() {\r\n    console.log('client online')\r\n    f = setInterval(function() {\r\n      client.send(new Stanza('foobar'));\r\n    }, 50);\r\n  });\r\n  client.on('stanza', function(stanza) {\r\n    console.log('server in', stanza.toString());\r\n  });\r\n  client.once('close', function() {\r\n    console.log('close');\r\n    clearInterval(f);\r\n  });\r\n\r\n});\r\n```\r\n\r\n### Client\r\n```javascript\r\n'use strict';\r\n\r\nvar Client = require('node-xmpp-client');\r\nvar Stanza = require('node-xmpp-core').Stanza.Stanza;\r\n\r\nvar client = new Client({\r\n  jid: 'foo@localhost/ab',\r\n  password: 'papapa',\r\n  autostart: true,\r\n  bosh: {\r\n    url: 'http://localhost:5281/http-bind'\r\n  }\r\n});\r\nclient.once('error', function(err) {\r\n  throw err;\r\n});\r\n\r\nclient.once('online', function() {\r\n  console.log('client', client.jid.toString(), 'online');\r\n});\r\n\r\nclient.on('stanza', function(stanza) {\r\n  console.log('client', client.jid.toString(), 'IN', stanza.toString());\r\n});\r\n\r\nclient.once('offline', function() {\r\n  console.log('client', client.jid.toString(), 'offline');\r\n});\r\n\r\n```\r\n\r\n# How to reproduce\r\n\r\nOpen a terminal and run ```node server.js```\r\nOpen a second terminal and run ```node client.js```\r\n\r\nOnce client is online server will send it data every 50ms (decrease the interval if you can't reproduce on your computer)\r\nKill the client.js process via ctrl+c.\r\n\r\n#### Expected result:\r\nserver process logs 'close' in the terminal and stop sending data to the client\r\n\r\n#### Actual result:\r\nserver process doesn't log 'close' event in the terminal and keep sending data to the (offline) client"}}