{"action":"created","issue":{"url":"https://api.github.com/repos/tessel/runtime/issues/709","labels_url":"https://api.github.com/repos/tessel/runtime/issues/709/labels{/name}","comments_url":"https://api.github.com/repos/tessel/runtime/issues/709/comments","events_url":"https://api.github.com/repos/tessel/runtime/issues/709/events","html_url":"https://github.com/tessel/runtime/issues/709","id":56758039,"number":709,"title":"TLS connection dies under ??? circumstances [even/at least under POSIX!]","user":{"login":"natevw","id":265902,"avatar_url":"https://avatars.githubusercontent.com/u/265902?v=3","gravatar_id":"","url":"https://api.github.com/users/natevw","html_url":"https://github.com/natevw","followers_url":"https://api.github.com/users/natevw/followers","following_url":"https://api.github.com/users/natevw/following{/other_user}","gists_url":"https://api.github.com/users/natevw/gists{/gist_id}","starred_url":"https://api.github.com/users/natevw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natevw/subscriptions","organizations_url":"https://api.github.com/users/natevw/orgs","repos_url":"https://api.github.com/users/natevw/repos","events_url":"https://api.github.com/users/natevw/events{/privacy}","received_events_url":"https://api.github.com/users/natevw/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-06T01:38:38Z","updated_at":"2015-02-09T22:29:55Z","closed_at":null,"body":"To reproduce, setup a key and start a local [proxy server](https://github.com/tessel/proxy) with your \"config/env\" file contents as such:\r\n\r\n```\r\nPORT=5005\r\nzzz_AUTH_TESSEL_OA2=http://tessel-proxy-dev:the-tessel-devenv@localhost:3002\r\nAUTH_HARDCODED=DEV-CRED\r\n```\r\n\r\nThen run this script under colony built from the https://github.com/tessel/runtime/pull/702 branch (also, note relative path to proxy's public key):\r\n\r\n```\r\nprocess.env._PROXY_DBG = true;\r\n//process.env.PROXY_HOST = \"proxy.192.168.4.114.xip.io\";\r\nprocess.env.PROXY_HOST = \"localhost\";\r\nprocess.env.PROXY_PORT = 5005;\r\nprocess.env.PROXY_TOKEN = \"DEV-CRED\";\r\nprocess.env.PROXY_CERT = require('fs').readFileSync(\"../proxy/config/public-cert.pem\").toString();\r\nprocess.env.PROXY_IDLE = 1e3;\r\n\r\nvar n = 0;\r\nfunction makeRequest() {\r\n  console.log(\"Making request\", ++n);\r\n  var req = require('http').request(\"http://dbg-\"+n+\".ipcalf.com/?format=text\", function(res) {\r\n    console.log(\"req status:\", res.statusCode);\r\n    res.on('data', function (d) {\r\n      console.log(\"req data:\", d.toString());\r\n    });\r\n    res.on('end', function () {\r\n      console.log(\"req done.\");\r\n    });\r\n  });\r\n  req.on('error', function (e) {\r\n    console.error(\"Problem with request:\", e.stack);\r\n  });\r\n  req.end();\r\n}\r\n\r\nsetInterval(makeRequest, 3e3);\r\nsetInterval(makeRequest, 100);\r\n```\r\n\r\nFor me the following happens: the client keeps rolling along but soon doesn't get any responses back. If you look in the **proxy** logs, you'll see it thinks that the client has disconnected after only a few requests.\r\n\r\n\r\n\r\n----\r\n\r\nNow's where it gets interesting. Apply this one-line change locally and rebuild colony:\r\n\r\n```\r\ndiff --git a/src/colony/modules/_net_proxied.js b/src/colony/modules/_net_proxied.js\r\nindex dec688f..278e223 100644\r\n--- a/src/colony/modules/_net_proxied.js\r\n+++ b/src/colony/modules/_net_proxied.js\r\n@@ -38,7 +38,8 @@ var _PROXY_DBG = ('_PROXY_DBG' in process.env) || false,\r\n \r\n function createTunnel(cb) {\r\n   if (_PROXY_DBG) console.log(\"TUNNEL -> START\", new Date());\r\n-  tls.connect({host:PROXY_HOST, port:PROXY_PORT, proxy:false, ca:[PROXY_CERT]}, function () {\r\n+  //tls.connect({host:PROXY_HOST, port:PROXY_PORT, proxy:false, ca:[PROXY_CERT]}, function () {\r\n+  net.connect({host:PROXY_HOST, port:PROXY_PORT, proxy:false, ca:[PROXY_CERT]}, function () {\r\n     var proxySocket = this,\r\n         tunnel = streamplex(streamplex.B_SIDE);\r\n     tunnel.pipe(proxySocket).pipe(tunnel);\r\n```\r\n\r\nDo the same change in the proxy's \"proxy.js\" file (i.e. swap `tls.createServer` for `net.createServer`) — it should restart automatically if you've used `npm start`.\r\n\r\nNow the tunnel connection will happen over plaintext socket for debugging — I originally did this so I could more easily see the pre-hangup tunnel data in Wireshark.\r\n\r\n**BUT** now when you run the client test script, it now goes properly gangbusters with the requests/responses working for a long time (eventually my DNS server seems to get upset with all my requests, but still the system behaves otherwise ± as expected in the situation).\r\n\r\nSo the cause of the original dropped connection seems to be somewhere in the `self._secure`/axTLS codepath. Haven't gotten much farther than that debugging."},"comment":{"url":"https://api.github.com/repos/tessel/runtime/issues/comments/73604643","html_url":"https://github.com/tessel/runtime/issues/709#issuecomment-73604643","issue_url":"https://api.github.com/repos/tessel/runtime/issues/709","id":73604643,"user":{"login":"natevw","id":265902,"avatar_url":"https://avatars.githubusercontent.com/u/265902?v=3","gravatar_id":"","url":"https://api.github.com/users/natevw","html_url":"https://github.com/natevw","followers_url":"https://api.github.com/users/natevw/followers","following_url":"https://api.github.com/users/natevw/following{/other_user}","gists_url":"https://api.github.com/users/natevw/gists{/gist_id}","starred_url":"https://api.github.com/users/natevw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natevw/subscriptions","organizations_url":"https://api.github.com/users/natevw/orgs","repos_url":"https://api.github.com/users/natevw/repos","events_url":"https://api.github.com/users/natevw/events{/privacy}","received_events_url":"https://api.github.com/users/natevw/received_events","type":"User","site_admin":false},"created_at":"2015-02-09T22:29:55Z","updated_at":"2015-02-09T22:29:55Z","body":"Reduced test case (still needs server cert, so easiest to test out of pre-configured proxy repo).\r\n\r\n\r\nClient:\r\n\r\n```\r\nrequire('tls').connect({port:5009, rejectUnauthorized:false}, function (sock) {\r\n  console.log(\"connected\");\r\n  var sock = this,\r\n      n = 0;\r\n  setInterval(function () {\r\n    sock.write((++n).toString());\r\n  }, 10);\r\n  sock.on('data', function (d) {\r\n    console.log(\"data:\", d.toString());\r\n  });\r\n});\r\n```\r\n\r\nServer:\r\n\r\n```\r\nvar fs = require('fs'),\r\n    tls = require('tls');\r\n\r\nvar PORT = +process.env.PORT || 5009,\r\n    CERT_FILE = process.env.CERT_FILE || \"config/public-cert.pem\",\r\n    KEY_FILE = process.env.KEY_FILE || \"config/private-key.pem\",\r\n    KEY_PASS = process.env.KEY_PASS;\r\n\r\ntls.createServer({\r\n  key: fs.readFileSync(KEY_FILE),\r\n  passphrase: KEY_PASS,\r\n  cert: fs.readFileSync(CERT_FILE)\r\n}, function (sock) {\r\n  console.log(\"socket connected\");\r\n  sock.on('data', function (d) {\r\n    console.log(\"data:\", d.toString());\r\n    sock.write(d);\r\n  });\r\n  sock.on('end', function () {\r\n    console.log(\"done\");\r\n  });\r\n  sock.on('close', function () {\r\n    console.log(\"socket closed\");\r\n  });  \r\n}).listen(PORT, function(){\r\n  console.log(\"listening on port\", this.address().port);\r\n});\r\n```\r\n\r\n\r\nWhen client is run under node, works fine. When client is run under colony, similar close behavior noted. It seems the interval is relevant: I did not encounter trouble when writing every `100` milliseconds, but did when writing every `10`.\r\n"}}