{"action":"created","issue":{"url":"https://api.github.com/repos/discordjs/discord.js/issues/2449","repository_url":"https://api.github.com/repos/discordjs/discord.js","labels_url":"https://api.github.com/repos/discordjs/discord.js/issues/2449/labels{/name}","comments_url":"https://api.github.com/repos/discordjs/discord.js/issues/2449/comments","events_url":"https://api.github.com/repos/discordjs/discord.js/issues/2449/events","html_url":"https://github.com/discordjs/discord.js/issues/2449","id":311766703,"number":2449,"title":"Discord making too many long-lasting TCP connections","user":{"login":"nzhammer","id":25111784,"avatar_url":"https://avatars1.githubusercontent.com/u/25111784?v=4","gravatar_id":"","url":"https://api.github.com/users/nzhammer","html_url":"https://github.com/nzhammer","followers_url":"https://api.github.com/users/nzhammer/followers","following_url":"https://api.github.com/users/nzhammer/following{/other_user}","gists_url":"https://api.github.com/users/nzhammer/gists{/gist_id}","starred_url":"https://api.github.com/users/nzhammer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nzhammer/subscriptions","organizations_url":"https://api.github.com/users/nzhammer/orgs","repos_url":"https://api.github.com/users/nzhammer/repos","events_url":"https://api.github.com/users/nzhammer/events{/privacy}","received_events_url":"https://api.github.com/users/nzhammer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-04-05T20:58:13Z","updated_at":"2018-04-06T19:11:03Z","closed_at":null,"author_association":"NONE","body":"<!--\r\nIf you need help with discord.js installation or usage, please go to the discord.js Discord server instead:\r\n  https://discord.gg/bRCvFy9\r\nThis issue tracker is only for bug reports and enhancement suggestions. You won't receive any basic help here.\r\n-->\r\n\r\n**Please describe the problem you are having in as much detail as possible:**\r\n\r\nWhen using channels.get(CHANNEL_ID).send(), I am noticing that my program makes a new TCP connection each time and that the TCP connection stays open for a very long time (maybe 3-5 minutes?).  The first .send() makes three TCP connections, and each subsequent .send() creates one additional TCP connection. This means that if I were to hypothetically send 47 messages to a channel in 3 minutes, I will have 50 TCP connections open.\r\n\r\nMy theory is that this is causing ESOCKETTIMEDOUT and ETIMEDOUT errors due to far too many TCP connections being opened, which is blocking I/O for my entire program and causing many issues. I am testing with a script that runs netstat every 5 seconds while my program runs and filtering on my node program's PID. At times when I have a higher number of .sends() being called, the TCP connections jump up and I often see ESOCKETTIMEDOUT errors.\r\n\r\nI do not understand why there is a new TCP connection for each .send() to the same channel and why they hang around for so long. Is there some way to kill the connection once the message has been acknowledged as delivered or can I use just one TCP connections for all sends to the same channel? Should I be doing this in a different way?\r\n\r\n\r\n**Include a reproducible code sample here, if possible:**\r\n\r\nAn example of my code to reproduce the issue:\r\n```js\r\n\r\nvar client = new Discord.Client();\r\nchannels = client.channels;\r\nclient.login(Config.LOGIN_TOKEN)\r\n\t.then(result => {\r\n\t\tvar channel = channels.get(CHANNEL_ID);\r\n                setInterval(function() {\r\n                   channel.send('some message');\r\n                }, 2000);\r\n\t})\r\n\r\n```\r\n\r\n**Further details:**\r\n\r\n- discord.js version: 11.3.0\r\n- node.js version: v8.9.2\r\n- Operating system: Windows 10\r\n- Priority this issue should have – please be realistic and elaborate if possible: It's preventing me from being able to use Discord in my application. Often causes errors to be thrown if I do use Discord.\r\n\r\n<!--\r\nIf either of these applies to you, please check the respective checkbox: [ ] becomes [x].\r\nYou don't have to modify the text to suit your particular situation, if you want to\r\nelaborate please do so in the description.\r\nWhile it's not a requirement to test your issue on the master branch, it would make fixing\r\nthe problem a lot easier for us, so please do it if possible.\r\n-->\r\n- [ ] I found this issue while running code on a __user account__\r\n- [ ] I have also tested the issue on latest master, commit hash:\r\n"},"comment":{"url":"https://api.github.com/repos/discordjs/discord.js/issues/comments/379349535","html_url":"https://github.com/discordjs/discord.js/issues/2449#issuecomment-379349535","issue_url":"https://api.github.com/repos/discordjs/discord.js/issues/2449","id":379349535,"user":{"login":"nzhammer","id":25111784,"avatar_url":"https://avatars1.githubusercontent.com/u/25111784?v=4","gravatar_id":"","url":"https://api.github.com/users/nzhammer","html_url":"https://github.com/nzhammer","followers_url":"https://api.github.com/users/nzhammer/followers","following_url":"https://api.github.com/users/nzhammer/following{/other_user}","gists_url":"https://api.github.com/users/nzhammer/gists{/gist_id}","starred_url":"https://api.github.com/users/nzhammer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nzhammer/subscriptions","organizations_url":"https://api.github.com/users/nzhammer/orgs","repos_url":"https://api.github.com/users/nzhammer/repos","events_url":"https://api.github.com/users/nzhammer/events{/privacy}","received_events_url":"https://api.github.com/users/nzhammer/received_events","type":"User","site_admin":false},"created_at":"2018-04-06T19:11:03Z","updated_at":"2018-04-06T19:11:03Z","author_association":"NONE","body":"@devsnek \r\nOk, I get what you're saying. I reformatted my POST in the following way in setInterval and there's only 1 TCP connection for all requests!\r\n\r\n```js\r\n\r\nsnekfetch.post('https://discordapp.com/api/v7/channels/<channel>/messages', {\r\n        agent: agent,\r\n\tdata: {\r\n\t    content: 'hello'\r\n\t},\r\n\theaders: {\r\n\t\t'Authorization': 'Bot <key>',\r\n\t\t'User-Agent': 'DiscordBot (https://github.com/hydrabolt/discord.js, 11.3.0) Node.js/v8.9.2'\r\n\t}\r\n\r\n})\r\n\r\n```\r\n\r\nThe problem is, this doesn't seem to be how the Discord code is formatting it, which may be the root of the issue. If you check APIRequest.js, it's more how I structured it above and it makes a new request for each .send() call."}}
{"actor":{"display_login":"nzhammer"}}