{"action":"closed","number":1002,"pull_request":{"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/1002","id":57936602,"html_url":"https://github.com/nodemcu/nodemcu-firmware/pull/1002","diff_url":"https://github.com/nodemcu/nodemcu-firmware/pull/1002.diff","patch_url":"https://github.com/nodemcu/nodemcu-firmware/pull/1002.patch","issue_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/1002","number":1002,"state":"closed","locked":false,"title":"Fix memory exhaustion in mqtt under circumstances from issue #975","user":{"login":"pjsg","id":1508813,"avatar_url":"https://avatars.githubusercontent.com/u/1508813?v=3","gravatar_id":"","url":"https://api.github.com/users/pjsg","html_url":"https://github.com/pjsg","followers_url":"https://api.github.com/users/pjsg/followers","following_url":"https://api.github.com/users/pjsg/following{/other_user}","gists_url":"https://api.github.com/users/pjsg/gists{/gist_id}","starred_url":"https://api.github.com/users/pjsg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pjsg/subscriptions","organizations_url":"https://api.github.com/users/pjsg/orgs","repos_url":"https://api.github.com/users/pjsg/repos","events_url":"https://api.github.com/users/pjsg/events{/privacy}","received_events_url":"https://api.github.com/users/pjsg/received_events","type":"User","site_admin":false},"body":"The root cause of the memory exhaustion is as follows:\r\n\r\n* The supplied example code (issue #975) publishes two messages every second.\r\n\r\n* Initially, the first message is sent and the second message is queued. \r\n* The socket calls back to say that the first message has been sent.\r\n\r\n* One second later the timer fires and sees that the socket is available and there is a queued packet, so it sends it.\r\n* At the same time, two more messages are published, and both get queued (as there is a message outstanding).\r\n* The socket calls back to say that the second message has been sent.\r\n\r\nAt this point there are two messages queued. The timer can get rid of one message per second, but the lua code is pumping in two messages per second. This is an ongoing getting worse situation and eventually we run out of memory.\r\n\r\nThe fix is easy -- when the socket calls back to say that the packet has been sent, check the outgoing queue to see if we should send another packet immediately. If so, send it. This is what this PR does. It also corrects the return code from :publish. \r\n\r\nIf you are using a non-zero QoS, then things aren't quite as simple, and I'm not sure if bad things can happen.\r\n\r\nThere is a lot of duplicated code in the mqtt module -- which I didn't fix. ","created_at":"2016-02-02T03:39:20Z","updated_at":"2016-02-10T11:58:26Z","closed_at":"2016-02-10T11:58:26Z","merged_at":"2016-02-10T11:58:26Z","merge_commit_sha":"ee2caa76b11f2710fbb1ea29d94bf12ba324ade1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/1002/commits","review_comments_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/1002/comments","review_comment_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/comments{/number}","comments_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/1002/comments","statuses_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/statuses/c9cf02ba3143025da8cb7d0345a7de8352eb72be","head":{"label":"pjsg:mqtt","ref":"mqtt","sha":"c9cf02ba3143025da8cb7d0345a7de8352eb72be","user":{"login":"pjsg","id":1508813,"avatar_url":"https://avatars.githubusercontent.com/u/1508813?v=3","gravatar_id":"","url":"https://api.github.com/users/pjsg","html_url":"https://github.com/pjsg","followers_url":"https://api.github.com/users/pjsg/followers","following_url":"https://api.github.com/users/pjsg/following{/other_user}","gists_url":"https://api.github.com/users/pjsg/gists{/gist_id}","starred_url":"https://api.github.com/users/pjsg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pjsg/subscriptions","organizations_url":"https://api.github.com/users/pjsg/orgs","repos_url":"https://api.github.com/users/pjsg/repos","events_url":"https://api.github.com/users/pjsg/events{/privacy}","received_events_url":"https://api.github.com/users/pjsg/received_events","type":"User","site_admin":false},"repo":{"id":47082038,"name":"nodemcu-firmware","full_name":"pjsg/nodemcu-firmware","owner":{"login":"pjsg","id":1508813,"avatar_url":"https://avatars.githubusercontent.com/u/1508813?v=3","gravatar_id":"","url":"https://api.github.com/users/pjsg","html_url":"https://github.com/pjsg","followers_url":"https://api.github.com/users/pjsg/followers","following_url":"https://api.github.com/users/pjsg/following{/other_user}","gists_url":"https://api.github.com/users/pjsg/gists{/gist_id}","starred_url":"https://api.github.com/users/pjsg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pjsg/subscriptions","organizations_url":"https://api.github.com/users/pjsg/orgs","repos_url":"https://api.github.com/users/pjsg/repos","events_url":"https://api.github.com/users/pjsg/events{/privacy}","received_events_url":"https://api.github.com/users/pjsg/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pjsg/nodemcu-firmware","description":"lua based interactive firmware for mcu like esp8266","fork":true,"url":"https://api.github.com/repos/pjsg/nodemcu-firmware","forks_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/forks","keys_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/teams","hooks_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/hooks","issue_events_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/issues/events{/number}","events_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/events","assignees_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/assignees{/user}","branches_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/branches{/branch}","tags_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/tags","blobs_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/git/refs{/sha}","trees_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/statuses/{sha}","languages_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/languages","stargazers_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/stargazers","contributors_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/contributors","subscribers_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/subscribers","subscription_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/subscription","commits_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/commits{/sha}","git_commits_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/git/commits{/sha}","comments_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/comments{/number}","issue_comment_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/issues/comments{/number}","contents_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/contents/{+path}","compare_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/merges","archive_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/downloads","issues_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/issues{/number}","pulls_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/pulls{/number}","milestones_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/milestones{/number}","notifications_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/labels{/name}","releases_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/releases{/id}","deployments_url":"https://api.github.com/repos/pjsg/nodemcu-firmware/deployments","created_at":"2015-11-29T21:58:51Z","updated_at":"2016-01-14T16:08:11Z","pushed_at":"2016-02-02T03:30:05Z","git_url":"git://github.com/pjsg/nodemcu-firmware.git","ssh_url":"git@github.com:pjsg/nodemcu-firmware.git","clone_url":"https://github.com/pjsg/nodemcu-firmware.git","svn_url":"https://github.com/pjsg/nodemcu-firmware","homepage":"http://nodemcu.com","size":87493,"stargazers_count":1,"watchers_count":1,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"nodemcu:dev","ref":"dev","sha":"fcb14a33b3aa17ba4173d2e70bc6e1ca1e036a98","user":{"login":"nodemcu","id":9865736,"avatar_url":"https://avatars.githubusercontent.com/u/9865736?v=3","gravatar_id":"","url":"https://api.github.com/users/nodemcu","html_url":"https://github.com/nodemcu","followers_url":"https://api.github.com/users/nodemcu/followers","following_url":"https://api.github.com/users/nodemcu/following{/other_user}","gists_url":"https://api.github.com/users/nodemcu/gists{/gist_id}","starred_url":"https://api.github.com/users/nodemcu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodemcu/subscriptions","organizations_url":"https://api.github.com/users/nodemcu/orgs","repos_url":"https://api.github.com/users/nodemcu/repos","events_url":"https://api.github.com/users/nodemcu/events{/privacy}","received_events_url":"https://api.github.com/users/nodemcu/received_events","type":"User","site_admin":false},"repo":{"id":26917568,"name":"nodemcu-firmware","full_name":"nodemcu/nodemcu-firmware","owner":{"login":"nodemcu","id":9865736,"avatar_url":"https://avatars.githubusercontent.com/u/9865736?v=3","gravatar_id":"","url":"https://api.github.com/users/nodemcu","html_url":"https://github.com/nodemcu","followers_url":"https://api.github.com/users/nodemcu/followers","following_url":"https://api.github.com/users/nodemcu/following{/other_user}","gists_url":"https://api.github.com/users/nodemcu/gists{/gist_id}","starred_url":"https://api.github.com/users/nodemcu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nodemcu/subscriptions","organizations_url":"https://api.github.com/users/nodemcu/orgs","repos_url":"https://api.github.com/users/nodemcu/repos","events_url":"https://api.github.com/users/nodemcu/events{/privacy}","received_events_url":"https://api.github.com/users/nodemcu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nodemcu/nodemcu-firmware","description":"lua based interactive firmware for mcu like esp8266","fork":false,"url":"https://api.github.com/repos/nodemcu/nodemcu-firmware","forks_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/forks","keys_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/teams","hooks_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/hooks","issue_events_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/events{/number}","events_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/events","assignees_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/assignees{/user}","branches_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/branches{/branch}","tags_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/tags","blobs_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/git/refs{/sha}","trees_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/statuses/{sha}","languages_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/languages","stargazers_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/stargazers","contributors_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/contributors","subscribers_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/subscribers","subscription_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/subscription","commits_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/commits{/sha}","git_commits_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/git/commits{/sha}","comments_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/comments{/number}","issue_comment_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/comments{/number}","contents_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/contents/{+path}","compare_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/merges","archive_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/downloads","issues_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues{/number}","pulls_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls{/number}","milestones_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/milestones{/number}","notifications_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/labels{/name}","releases_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/releases{/id}","deployments_url":"https://api.github.com/repos/nodemcu/nodemcu-firmware/deployments","created_at":"2014-11-20T15:06:45Z","updated_at":"2016-02-10T02:31:42Z","pushed_at":"2016-02-10T11:58:27Z","git_url":"git://github.com/nodemcu/nodemcu-firmware.git","ssh_url":"git@github.com:nodemcu/nodemcu-firmware.git","clone_url":"https://github.com/nodemcu/nodemcu-firmware.git","svn_url":"https://github.com/nodemcu/nodemcu-firmware","homepage":"http://nodemcu.com","size":103712,"stargazers_count":1844,"watchers_count":1844,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":837,"mirror_url":null,"open_issues_count":111,"forks":837,"open_issues":111,"watchers":1844,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/1002"},"html":{"href":"https://github.com/nodemcu/nodemcu-firmware/pull/1002"},"issue":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/1002"},"comments":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/issues/1002/comments"},"review_comments":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/1002/comments"},"review_comment":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/pulls/1002/commits"},"statuses":{"href":"https://api.github.com/repos/nodemcu/nodemcu-firmware/statuses/c9cf02ba3143025da8cb7d0345a7de8352eb72be"}},"merged":true,"mergeable":null,"mergeable_state":"unknown","merged_by":{"login":"marcelstoer","id":624195,"avatar_url":"https://avatars.githubusercontent.com/u/624195?v=3","gravatar_id":"","url":"https://api.github.com/users/marcelstoer","html_url":"https://github.com/marcelstoer","followers_url":"https://api.github.com/users/marcelstoer/followers","following_url":"https://api.github.com/users/marcelstoer/following{/other_user}","gists_url":"https://api.github.com/users/marcelstoer/gists{/gist_id}","starred_url":"https://api.github.com/users/marcelstoer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcelstoer/subscriptions","organizations_url":"https://api.github.com/users/marcelstoer/orgs","repos_url":"https://api.github.com/users/marcelstoer/repos","events_url":"https://api.github.com/users/marcelstoer/events{/privacy}","received_events_url":"https://api.github.com/users/marcelstoer/received_events","type":"User","site_admin":false},"comments":3,"review_comments":0,"commits":1,"additions":28,"deletions":10,"changed_files":1}}