{"action":"created","issue":{"url":"https://api.github.com/repos/Azure/azure-iot-sdk-node/issues/221","repository_url":"https://api.github.com/repos/Azure/azure-iot-sdk-node","labels_url":"https://api.github.com/repos/Azure/azure-iot-sdk-node/issues/221/labels{/name}","comments_url":"https://api.github.com/repos/Azure/azure-iot-sdk-node/issues/221/comments","events_url":"https://api.github.com/repos/Azure/azure-iot-sdk-node/issues/221/events","html_url":"https://github.com/Azure/azure-iot-sdk-node/issues/221","id":294745790,"number":221,"title":"Device client fails on disconnect using AMQP/AMQP-WS (using NoRetry policy)","user":{"login":"wmmihaa","id":3214367,"avatar_url":"https://avatars2.githubusercontent.com/u/3214367?v=4","gravatar_id":"","url":"https://api.github.com/users/wmmihaa","html_url":"https://github.com/wmmihaa","followers_url":"https://api.github.com/users/wmmihaa/followers","following_url":"https://api.github.com/users/wmmihaa/following{/other_user}","gists_url":"https://api.github.com/users/wmmihaa/gists{/gist_id}","starred_url":"https://api.github.com/users/wmmihaa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wmmihaa/subscriptions","organizations_url":"https://api.github.com/users/wmmihaa/orgs","repos_url":"https://api.github.com/users/wmmihaa/repos","events_url":"https://api.github.com/users/wmmihaa/events{/privacy}","received_events_url":"https://api.github.com/users/wmmihaa/received_events","type":"User","site_admin":false},"labels":[{"id":512640578,"url":"https://api.github.com/repos/Azure/azure-iot-sdk-node/labels/investigation-required","name":"investigation-required","color":"649ec1","default":false}],"state":"open","locked":false,"assignee":{"login":"anthonyvercolano","id":9854568,"avatar_url":"https://avatars0.githubusercontent.com/u/9854568?v=4","gravatar_id":"","url":"https://api.github.com/users/anthonyvercolano","html_url":"https://github.com/anthonyvercolano","followers_url":"https://api.github.com/users/anthonyvercolano/followers","following_url":"https://api.github.com/users/anthonyvercolano/following{/other_user}","gists_url":"https://api.github.com/users/anthonyvercolano/gists{/gist_id}","starred_url":"https://api.github.com/users/anthonyvercolano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anthonyvercolano/subscriptions","organizations_url":"https://api.github.com/users/anthonyvercolano/orgs","repos_url":"https://api.github.com/users/anthonyvercolano/repos","events_url":"https://api.github.com/users/anthonyvercolano/events{/privacy}","received_events_url":"https://api.github.com/users/anthonyvercolano/received_events","type":"User","site_admin":false},"assignees":[{"login":"anthonyvercolano","id":9854568,"avatar_url":"https://avatars0.githubusercontent.com/u/9854568?v=4","gravatar_id":"","url":"https://api.github.com/users/anthonyvercolano","html_url":"https://github.com/anthonyvercolano","followers_url":"https://api.github.com/users/anthonyvercolano/followers","following_url":"https://api.github.com/users/anthonyvercolano/following{/other_user}","gists_url":"https://api.github.com/users/anthonyvercolano/gists{/gist_id}","starred_url":"https://api.github.com/users/anthonyvercolano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anthonyvercolano/subscriptions","organizations_url":"https://api.github.com/users/anthonyvercolano/orgs","repos_url":"https://api.github.com/users/anthonyvercolano/repos","events_url":"https://api.github.com/users/anthonyvercolano/events{/privacy}","received_events_url":"https://api.github.com/users/anthonyvercolano/received_events","type":"User","site_admin":false}],"milestone":null,"comments":4,"created_at":"2018-02-06T12:43:47Z","updated_at":"2018-02-06T23:01:41Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"# Context\r\n- **OS and version used:** Windows 10, Ubuntu 16.4... -->\r\n- **Node.js version:** 7.10, 6.11\r\n- **npm version:** 4.2\r\n- **list of installed packages:** <VERSION> <!-- in a command prompt, from the directory containing your code: npm list \r\n\"azure-iot-common\": \"^1.3.0\",\r\n    \"azure-iot-device\": \"^1.3.0\",\r\n    \"azure-iot-device-amqp\": \"^1.3.0\",\r\n    \"azure-iot-device-mqtt\": \"^1.3.0\",\r\n    \"color\": \"^3.0.0\",\r\n    \"colors\": \"^1.1.2\"\r\n\r\n# Description of the issue:\r\nDevice client fails on disconnect using AMQP/AMQP-WS\r\n\r\n# Code sample exhibiting the issue:\r\n```javascript\r\n'use strict';\r\n\r\nrequire('colors');\r\nvar DeviceClient = require('azure-iot-device').Client;\r\nvar Message = require('azure-iot-common').Message;;\r\nvar DeviceProtocol;\r\nvar connectionString = 'XXXXX';\r\nvar messageCount = 0;\r\nvar messageSentCount = 0;\r\nif (process.argv.length !== 3) {\r\n    console.log(\"Usage: node app [-amqp | -amqpws | -mqtt | -mqttws]\".yellow);\r\n    return;\r\n}\r\n\r\nconsole.log();\r\n\r\nswitch (process.argv[2].toLowerCase()) {\r\n    case \"-amqp\":\r\n    case \"amqp\":\r\n        console.log('Using AMQP'.green);\r\n        DeviceProtocol = require('azure-iot-device-amqp').Amqp;\r\n        break;\r\n    case \"-amqpws\":\r\n    case \"amqpws\":\r\n        console.log('Using AMQP-WS'.green);\r\n        DeviceProtocol = require('azure-iot-device-amqp').AmqpWs;\r\n        break;\r\n    case \"-mqtt\":\r\n    case \"mqtt\":\r\n        console.log('Using MQTT'.green);\r\n        DeviceProtocol = require('azure-iot-device-mqtt').Mqtt;\r\n        break;\r\n    case \"-mqttws\":\r\n    case \"mqttws\":\r\n        console.log('Using MQTT-WS'.green);\r\n        DeviceProtocol = require('azure-iot-device-mqtt').MqttWs;\r\n        break;\r\n    default:\r\n        console.log('Unsupported protocol'.red);\r\n        console.log(\"Usage: node app [-amqp | -amqpws | -mqtt | -mqttws]\".yellow);\r\n        break;\r\n\r\n}\r\n\r\nvar deviceClient = DeviceClient.fromConnectionString(connectionString, DeviceProtocol);\r\n// Disable retry policy\r\nlet NoRetry = require('azure-iot-common').NoRetry;\r\ndeviceClient.setRetryPolicy(new NoRetry());\r\n\r\ndeviceClient.open(function (err, transport) {\r\n    if (err) {\r\n        console.log('ERROR: '.red + err.message.red);\r\n        process.abort();\r\n    }\r\n    else {\r\n        console.log('AZURE IoT: Connected'.green);\r\n        deviceClient.on('disconnect', function () {\r\n            console.log('AZURE IoT: Disconnected'.bgGreen.white);\r\n        });\r\n        deviceClient.on('error', function (err) {\r\n            console.log('AZURE IoT: Error: '.red + err.message.red);\r\n        });\r\n        deviceClient.getTwin(function (err, twin) {\r\n            if (err) {\r\n                console.log('AZURE IoT: Could not get twin: '.red + err.message.red);\r\n            }\r\n            else {\r\n                console.log(\"AZURE IoT: Device twin is ready\".green);\r\n                twin.on('properties.desired', function (desiredChange) {\r\n                    console.log(\"AZURE IoT: Received new state\".green);\r\n                    console.log(\"\");\r\n                    sendEvents();\r\n                });\r\n            }\r\n        });\r\n    }\r\n});\r\n\r\nfunction sendEvents() {\r\n\r\n    setInterval(function () {\r\n        messageCount++;\r\n        var message = new Message(JSON.stringify({ dt: new Date(), messageCount: messageCount }));\r\n        deviceClient.sendEvent(message, function (err) {\r\n            messageSentCount ++ ;\r\n            if (err) {\r\n                let m = 'Unable to send message to to Azure IoT Hub  ' + messageSentCount + '/(' + messageCount + ')';\r\n                console.log(m.red);\r\n            }\r\n            else {\r\n                let m = 'Event has been sent to Azure IoT Hub  ' + messageSentCount + '/(' + messageCount + ')';\r\n                console.log(m.green);\r\n            }\r\n            \r\n        });\r\n    }, 5000);\r\n\r\n}\r\n```\r\n# Reproduce issue\r\n1. Open a console (don't rurn in VS Code)\r\n2. RUN: npm i azure-iot-common@1.3.0 azure-iot-device@1.3.0 azure-iot-device-amqp@1.3.0 azure-iot-device-mqtt@1.3.0 colors@1.1.2\r\n3. Type:\r\n```\r\nnpm app amqp\r\n```\r\n4. Disable wireless network adapter\r\n\r\n# Console log of the issue:\r\n\r\n```bash\r\nλ node app.js amqpws\r\n\r\nUsing AMQP-WS\r\nAZURE IoT: Connected\r\nAZURE IoT: Device twin is ready\r\nAZURE IoT: Received new state\r\n\r\nEvent has been sent to Azure IoT Hub  1/(1)\r\nUnable to send message to to Azure IoT Hub  2/(5)\r\nUnable to send message to to Azure IoT Hub  3/(5)\r\nUnable to send message to to Azure IoT Hub  4/(5)\r\nUnable to send message to to Azure IoT Hub  5/(5)\r\nAZURE IoT: Disconnected\r\nC:\\temp\\deviceConnectivityTest\\node_modules\\azure-iot-amqp-base\\lib\\amqp.js:109\r\n                        callback();\r\n                        ^\r\n\r\nTypeError: callback is not a function\r\n    at constructor.amqpError (C:\\temp\\deviceConnectivityTest\\node_modules\\azure-iot-amqp-base\\lib\\amqp.js:109:25)\r\n    at constructor.handle (C:\\temp\\deviceConnectivityTest\\node_modules\\machina\\lib\\machina.js:613:25)\r\n    at constructor.Fsm.(anonymous function) [as handle] (C:\\temp\\deviceConnectivityTest\\node_modules\\machina\\lib\\machina.js:466:63)\r\n    at constructor.<anonymous> (C:\\temp\\deviceConnectivityTest\\node_modules\\machina\\lib\\machina.js:702:17)\r\n    at C:\\temp\\deviceConnectivityTest\\node_modules\\machina\\node_modules\\lodash\\index.js:2874:23\r\n    at C:\\temp\\deviceConnectivityTest\\node_modules\\machina\\node_modules\\lodash\\index.js:3049:15\r\n    at Function.<anonymous> (C:\\temp\\deviceConnectivityTest\\node_modules\\machina\\node_modules\\lodash\\index.js:3346:13)\r\n    at constructor.processQueue (C:\\temp\\deviceConnectivityTest\\node_modules\\machina\\lib\\machina.js:701:6)\r\n    at constructor.Fsm.(anonymous function) [as processQueue] (C:\\temp\\deviceConnectivityTest\\node_modules\\machina\\lib\\machina.js:466:63)\r\n    at constructor.transition (C:\\temp\\deviceConnectivityTest\\node_modules\\machina\\lib\\machina.js:661:12)\r\n    at constructor.Fsm.(anonymous function) [as transition] (C:\\temp\\deviceConnectivityTest\\node_modules\\machina\\lib\\machina.js:466:63)\r\n    at C:\\temp\\deviceConnectivityTest\\node_modules\\azure-iot-amqp-base\\lib\\amqp.js:366:48\r\n    at disconnect (C:\\temp\\deviceConnectivityTest\\node_modules\\azure-iot-amqp-base\\lib\\amqp.js:319:33)\r\n    at C:\\temp\\deviceConnectivityTest\\node_modules\\azure-iot-amqp-base\\lib\\amqp.js:363:33\r\n    at C:\\temp\\deviceConnectivityTest\\node_modules\\async\\dist\\async.js:473:16\r\n    at iteratorCallback (C:\\temp\\deviceConnectivityTest\\node_modules\\async\\dist\\async.js:1050:13)\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/Azure/azure-iot-sdk-node/issues/comments/363595160","html_url":"https://github.com/Azure/azure-iot-sdk-node/issues/221#issuecomment-363595160","issue_url":"https://api.github.com/repos/Azure/azure-iot-sdk-node/issues/221","id":363595160,"user":{"login":"wmmihaa","id":3214367,"avatar_url":"https://avatars2.githubusercontent.com/u/3214367?v=4","gravatar_id":"","url":"https://api.github.com/users/wmmihaa","html_url":"https://github.com/wmmihaa","followers_url":"https://api.github.com/users/wmmihaa/followers","following_url":"https://api.github.com/users/wmmihaa/following{/other_user}","gists_url":"https://api.github.com/users/wmmihaa/gists{/gist_id}","starred_url":"https://api.github.com/users/wmmihaa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wmmihaa/subscriptions","organizations_url":"https://api.github.com/users/wmmihaa/orgs","repos_url":"https://api.github.com/users/wmmihaa/repos","events_url":"https://api.github.com/users/wmmihaa/events{/privacy}","received_events_url":"https://api.github.com/users/wmmihaa/received_events","type":"User","site_admin":false},"created_at":"2018-02-06T23:01:41Z","updated_at":"2018-02-06T23:01:41Z","author_association":"CONTRIBUTOR","body":"Here you go...\r\n\r\n[221.log](https://github.com/Azure/azure-iot-sdk-node/files/1701126/221.log)\r\n"}}
{"actor":{"display_login":"wmmihaa"}}