{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/15081","repository_url":"https://api.github.com/repos/nodejs/node","labels_url":"https://api.github.com/repos/nodejs/node/issues/15081/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/15081/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/15081/events","html_url":"https://github.com/nodejs/node/issues/15081","id":253840060,"number":15081,"title":"setInterval randomly intrudes in microtask queue","user":{"login":"vsemozhetbyt","id":10393198,"avatar_url":"https://avatars1.githubusercontent.com/u/10393198?v=4","gravatar_id":"","url":"https://api.github.com/users/vsemozhetbyt","html_url":"https://github.com/vsemozhetbyt","followers_url":"https://api.github.com/users/vsemozhetbyt/followers","following_url":"https://api.github.com/users/vsemozhetbyt/following{/other_user}","gists_url":"https://api.github.com/users/vsemozhetbyt/gists{/gist_id}","starred_url":"https://api.github.com/users/vsemozhetbyt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vsemozhetbyt/subscriptions","organizations_url":"https://api.github.com/users/vsemozhetbyt/orgs","repos_url":"https://api.github.com/users/vsemozhetbyt/repos","events_url":"https://api.github.com/users/vsemozhetbyt/events{/privacy}","received_events_url":"https://api.github.com/users/vsemozhetbyt/received_events","type":"User","site_admin":false},"labels":[{"id":340436277,"url":"https://api.github.com/repos/nodejs/node/labels/promises","name":"promises","color":"f7c6c7","default":false},{"id":155435976,"url":"https://api.github.com/repos/nodejs/node/labels/timers","name":"timers","color":"f7c6c7","default":false}],"state":"open","locked":false,"assignee":{"login":"Fishrock123","id":1093990,"avatar_url":"https://avatars0.githubusercontent.com/u/1093990?v=4","gravatar_id":"","url":"https://api.github.com/users/Fishrock123","html_url":"https://github.com/Fishrock123","followers_url":"https://api.github.com/users/Fishrock123/followers","following_url":"https://api.github.com/users/Fishrock123/following{/other_user}","gists_url":"https://api.github.com/users/Fishrock123/gists{/gist_id}","starred_url":"https://api.github.com/users/Fishrock123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fishrock123/subscriptions","organizations_url":"https://api.github.com/users/Fishrock123/orgs","repos_url":"https://api.github.com/users/Fishrock123/repos","events_url":"https://api.github.com/users/Fishrock123/events{/privacy}","received_events_url":"https://api.github.com/users/Fishrock123/received_events","type":"User","site_admin":false},"assignees":[{"login":"Fishrock123","id":1093990,"avatar_url":"https://avatars0.githubusercontent.com/u/1093990?v=4","gravatar_id":"","url":"https://api.github.com/users/Fishrock123","html_url":"https://github.com/Fishrock123","followers_url":"https://api.github.com/users/Fishrock123/followers","following_url":"https://api.github.com/users/Fishrock123/following{/other_user}","gists_url":"https://api.github.com/users/Fishrock123/gists{/gist_id}","starred_url":"https://api.github.com/users/Fishrock123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fishrock123/subscriptions","organizations_url":"https://api.github.com/users/Fishrock123/orgs","repos_url":"https://api.github.com/users/Fishrock123/repos","events_url":"https://api.github.com/users/Fishrock123/events{/privacy}","received_events_url":"https://api.github.com/users/Fishrock123/received_events","type":"User","site_admin":false}],"milestone":null,"comments":32,"created_at":"2017-08-30T00:04:39Z","updated_at":"2017-08-30T16:51:46Z","closed_at":null,"author_association":"MEMBER","body":"* **Version**: 8.4.0\r\n* **Platform**: Windows 7 x64\r\n* **Subsystem**: libuv, promises\r\n\r\nRevisiting [this article](https://blog.risingstack.com/node-js-at-scale-understanding-node-js-event-loop/), I've found out that [an example](https://blog.risingstack.com/node-js-at-scale-understanding-node-js-event-loop/#anamemicrotasksmacrotasksamicrotasksandmacrotasks) which illustrates some known bug (?) in microtask queue execution behaves differently because of times of script call.\r\n```js\r\n'use strict';\r\n\r\nconsole.log('script start')\r\n\r\nconst interval = setInterval(() => {  \r\n  console.log('setInterval')\r\n}, 0)\r\n\r\nsetTimeout(() => {  \r\n  console.log('setTimeout 1')\r\n  Promise.resolve().then(() => {\r\n    console.log('promise 3')\r\n  }).then(() => {\r\n    console.log('promise 4')\r\n  }).then(() => {\r\n    setTimeout(() => {\r\n      console.log('setTimeout 2')          //< place of random microtask queue intrusion\r\n      Promise.resolve().then(() => {\r\n        console.log('promise 5')\r\n      }).then(() => {\r\n        console.log('promise 6')\r\n      }).then(() => {\r\n        clearInterval(interval)\r\n      })\r\n    }, 0)\r\n  })\r\n}, 0)\r\n\r\nPromise.resolve().then(() => {  \r\n  console.log('promise 1')\r\n}).then(() => {\r\n  console.log('promise 2')\r\n})\r\n```\r\nEvery first call in a new `cmd.exe` terminal produces the mentioned error. Every next call has proper execution order:\r\n```console\r\n>node test.js\r\nscript start\r\npromise 1\r\npromise 2\r\nsetInterval\r\nsetTimeout 1\r\npromise 3\r\npromise 4\r\nsetInterval\r\nsetTimeout 2\r\nsetInterval          //< intruder\r\npromise 5\r\npromise 6\r\n\r\n>node test.js\r\nscript start\r\npromise 1\r\npromise 2\r\nsetInterval\r\nsetTimeout 1\r\npromise 3\r\npromise 4\r\nsetInterval\r\nsetTimeout 2\r\npromise 5\r\npromise 6\r\n```\r\nCompare the next step after the `setTimeout 2` output."},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/326051922","html_url":"https://github.com/nodejs/node/issues/15081#issuecomment-326051922","issue_url":"https://api.github.com/repos/nodejs/node/issues/15081","id":326051922,"user":{"login":"vsemozhetbyt","id":10393198,"avatar_url":"https://avatars1.githubusercontent.com/u/10393198?v=4","gravatar_id":"","url":"https://api.github.com/users/vsemozhetbyt","html_url":"https://github.com/vsemozhetbyt","followers_url":"https://api.github.com/users/vsemozhetbyt/followers","following_url":"https://api.github.com/users/vsemozhetbyt/following{/other_user}","gists_url":"https://api.github.com/users/vsemozhetbyt/gists{/gist_id}","starred_url":"https://api.github.com/users/vsemozhetbyt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vsemozhetbyt/subscriptions","organizations_url":"https://api.github.com/users/vsemozhetbyt/orgs","repos_url":"https://api.github.com/users/vsemozhetbyt/repos","events_url":"https://api.github.com/users/vsemozhetbyt/events{/privacy}","received_events_url":"https://api.github.com/users/vsemozhetbyt/received_events","type":"User","site_admin":false},"created_at":"2017-08-30T16:51:46Z","updated_at":"2017-08-30T16:51:46Z","author_association":"MEMBER","body":"Concerning my questions. Is this [answer](https://stackoverflow.com/questions/25915634/difference-between-microtask-and-macrotask-within-an-event-loop-context/25933985#25933985), referenced in some place, applicable for Node.js?\r\n\r\nIn both cases, this output fragment still seems strange:\r\n```\r\nsetInterval\r\nsetTimeout 2\r\nsetInterval \r\npromise 5\r\npromise 6\r\n```\r\nHow can we parse it if the answer is true?\r\n```txt\r\n--------------------event loop go-around 1\r\nsetInterval\r\n--------------------event loop go-around 2\r\nsetTimeout 2\r\n--------------------event loop go-around 3\r\nsetInterval \r\npromise 5\r\npromise 6\r\n```\r\nThis seem not OK: in the event loop go-around 3 we have microtask queue from the event loop go-around 2.\r\nIf the answer is not true, what would be the separation?\r\n```txt\r\n--------------------event loop go-around 1\r\nsetInterval\r\nsetTimeout 2\r\n--------------------event loop go-around 2\r\nsetInterval \r\npromise 5\r\npromise 6\r\n```\r\nWe still have microtask queue from the previous loop go-around.\r\n```txt\r\n--------------------event loop go-around 1\r\nsetInterval\r\n--------------------event loop go-around 2\r\nsetTimeout 2\r\nsetInterval \r\npromise 5\r\npromise 6\r\n```\r\nWe have one missing macrotask in the event loop go-around 1\r\n```txt\r\n--------------------event loop go-around 1\r\nsetInterval\r\nsetTimeout 2\r\nsetInterval \r\npromise 5\r\npromise 6\r\n```\r\nWe have two identical macrotasks in one event loop go-around\r\n"}}
{"actor":{"display_login":"vsemozhetbyt"}}