{ "id": "155714", "key": "TIMOB-20596", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": null, "resolutiondate": null, "created": "2016-03-14T11:05:29.000+0000", "priority": null, "labels": [], "versions": [ { "id": "16997", "name": "Release 5.2.0", "archived": false, "released": true, "releaseDate": "2016-02-23" } ], "issuelinks": [], "assignee": null, "updated": "2018-02-28T19:54:49.000+0000", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "components": [], "description": "Running a long loop of HTTP POSTs crashes due to a connection leak.\r\n\r\nI suspect it's a bug in HttpURLConnection. (I switched to a module running over okhttp with connection pooling, to work around this.)\r\n\r\nCode to reproduce follows.\r\n\r\nNotes:\r\n# Let the code run for awhile. For me it crashes at around 350 iterations.\r\n# I advise to change the REST server to something private because jsonplaceholder.typicode.com is very slow.\r\n# Uncommenting the line {{xhr.setRequestHeader(\"Connection\",\"Close\");}} will stop the leak, but then it's goodbye persistent connection.\r\n\r\n{code:title=app.js|borderStyle=solid}\r\nvar mainview = Ti.UI.createView();\r\nvar label = Ti.UI.createLabel({color:'black', text:'Click to start', height:'auto', width:'auto'});\r\nmainview.add(label);\r\nvar window = Ti.UI.createWindow({backgroundColor:'#ffffff', navBarHidden:true, exitOnClose:true});\r\nwindow.add(mainview);\r\n\r\nvar count = 0;\r\n\r\nfunction callApi(callback) {\r\n var cmdurl=\"http://jsonplaceholder.typicode.com/posts/\";\r\n var params={title:'the title',body:'see how far we can go...',userId:666};\r\n var httpmode=(params._httpmode)?params._httpmode:\"POST\";\r\n var xhr = Ti.Network.createHTTPClient();\r\n xhr.timeout=15000;\r\n xhr.open(\"POST\",cmdurl);\r\n// xhr.setRequestHeader(\"Connection\",\"Close\"); // This will fix the leak but will cost us the persistent connection. see http://stackoverflow.com/a/20417556/2603965\r\n xhr.onerror = function(e) {\r\n callback();\r\n };\r\n xhr.onload = function() {\r\n var d=false;\r\n try {\r\n d=JSON.parse(this.responseText);\r\n } catch(e) {\r\n d=false;\r\n }\r\n if (!d) {\r\n callback();\r\n } else {\r\n callback(d);\r\n }\r\n };\r\n xhr.send(params);\r\n};\r\n\r\nfunction printReply(d) {\r\n if (count > 0) {\r\n if (d) {\r\n label.applyProperties({text:'ok ' + count, color:'black'});\r\n Ti.API.info(\"HTTP TEST - count: \" + count /*+ \" - \" + JSON.stringify(d)*/);\r\n } else {\r\n label.applyProperties({text:'error ' + count, color:'red'});\r\n Ti.API.warn(\"HTTP TEST - count: \" + count);\r\n }\r\n }\r\n count++;\r\n setTimeout(function() {\r\n callApi(printReply);\r\n }, 10);\r\n};\r\n\r\nlabel.addEventListener('click', function(e) {\r\n Ti.API.info(\"HTTP TEST - start\");\r\n printReply();\r\n});\r\n\r\nwindow.open();\r\n{code}", "attachment": [], "flagged": false, "summary": "Android: HTTPClient leaking connections ", "creator": { "name": "buddyguards", "key": "buddyguards", "displayName": "grebulon", "active": true, "timeZone": "Asia/Jerusalem" }, "subtasks": [], "reporter": { "name": "buddyguards", "key": "buddyguards", "displayName": "grebulon", "active": true, "timeZone": "Asia/Jerusalem" }, "environment": "Ti 5.2.0\r\nAndroid 4, 5, 6", "comment": { "comments": [ { "id": "379723", "author": { "name": "nsalahin", "key": "nsalahin", "displayName": "Nazmus Salahin", "active": true, "timeZone": "Asia/Dhaka" }, "body": "I am not been able to reproduce this issue with the given code and given steps. After over 1000 iterations the app running without any problem or crash or console log and the iteration continues. I have tried building the app with sdk 5.2.0 and 5.1.2GA and got the same result.\r\n\r\n*Environment*:\r\n\r\n*Device info:* Nexux7 (android 6.0.1)\r\n*Node.js Version:* 0.12.7\r\n*npm Version:* 2.11.3\r\n*Titanium SDKs:* 5.2.0 and 5.1.2.GA\r\n*Java Development Kit Version:* 1.8.0_73\r\n*Titanium CLI Version:* 5.0.5", "updateAuthor": { "name": "cng", "key": "cng", "displayName": "Chee Kiat Ng", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2016-03-15T08:49:30.000+0000", "updated": "2016-03-21T02:30:18.000+0000" } ], "maxResults": 1, "total": 1, "startAt": 0 } } }