Title: F-stack rack and BBR both causes PCB memory leak · Issue #702 · F-Stack/f-stack · GitHub
Open Graph Title: F-stack rack and BBR both causes PCB memory leak · Issue #702 · F-Stack/f-stack
X Title: F-stack rack and BBR both causes PCB memory leak · Issue #702 · F-Stack/f-stack
Description: My application suddenly start spamming ff_socket: "No buffer space available." so I went to debug why. I figured out that setting tcp stack back to default freebsd stack solved the issue, it only happens on tcp stack to rack/bbr. Also do...
Open Graph Description: My application suddenly start spamming ff_socket: "No buffer space available." so I went to debug why. I figured out that setting tcp stack back to default freebsd stack solved the issue, it only h...
X Description: My application suddenly start spamming ff_socket: "No buffer space available." so I went to debug why. I figured out that setting tcp stack back to default freebsd stack solved the issue,...
Opengraph URL: https://github.com/F-Stack/f-stack/issues/702
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"F-stack rack and BBR both causes PCB memory leak","articleBody":"My application suddenly start spamming `ff_socket: \"No buffer space available.\"` so I went to debug why. I figured out that setting tcp stack back to default freebsd stack solved the issue, it only happens on tcp stack to rack/bbr. Also does not happen unless socket is bound and connected (leak is in pcb), so test case must cover that.\r\n\r\nAfter debugging for a couple hours, i think it is stemming from tcphpts. \r\nI spewed logs in certain places to get insight. Hopefully the info can be helpful for you to get to the bottom of it.\r\n\r\nHere is logs when using freebsd stack.\r\nFirst log shows that a 4th pcb has been allocated, for total of 4 currently allocated. Middle lines show the socket creation and instant destruction, basically `ff_socket, ff_bind, ff_connect, ff_close` combo. Expected refcnt increases/decreases. Very last line shows that the pcb is getting freed, and down to 3 currently handed out. Looks good!\r\n```\r\nALLOC 4\r\ntcp_newtopcb do thing 0\r\nIN_PCBREF INCR REF: 1 -\u003e 2\r\ntcp_usr_detach\r\nDISCARD CB!\r\nDRAINCNT IS 0\r\nDO PCB RELE\r\nIN_PCBRELE_WLOCKED DECR REF: 2 -\u003e 1\r\nRELEASE RET ZERO! 1\r\nin_pcbfree CALLED! SCHEDULE DEFERRED.\r\nin_pcbfree_deferred!\r\nIN_PCBRELE_WLOCKED DECR REF: 1 -\u003e 0\r\nPCB RELE WLOCKED 3\r\n```\r\n\r\nHere's logs with rack/bbr stack enabled. Now we see tcp hpts is adding a refcnt, which didn't happen before, but does not seem to be decreasing it. I have twiddled with tcp timewait/keepalive settings and brought them down to very low values, and let it sit there for hours in hopes to see it eventually release, but nope. Socket was not given nearly enough time to *actually* connect so i don't think that would be the issue anyways.\r\n\r\nso, in_pcbfree sets `INP_FREED` flag, which is picked up during in_pcbfree_deferred's call to in_pcbrele_wlocked, however during that call the refcnt is still 2, so somebody else is holding ref (appears to be tcphpts) meaning it can't be freed yet. \r\n\r\n```\r\nALLOC 4\r\ntcp_newtopcb do thing 0\r\nIN_PCBREF INCR REF: 1 -\u003e 2\r\nhpts do thing 0\r\nIN_PCBREF INCR REF: 2 -\u003e 3\r\ntcp_usr_detach\r\nDISCARD CB!\r\nDRAINCNT IS 0\r\nDO PCB RELE\r\nIN_PCBRELE_WLOCKED DECR REF: 3 -\u003e 2\r\nRELEASE RET ZERO! 2\r\nin_pcbfree CALLED! SCHEDULE DEFERRED.\r\nin_pcbfree_deferred!\r\nIN_PCBRELE_WLOCKED DECR REF: 2 -\u003e 1\r\nRELEASE RET ZERO! 1\r\nFLAG IS FREED!\r\n```\r\n\r\nTest case can be similar to #679 except also binds/connects to some host, then instant ff_close.\r\n\r\nWill run forever with freebsd stack without issue, will exit with these logs on bbr or rack stack:\r\n```\r\nff_socket: No buffer space available\r\nff_socket failed, fd:-1, errno:105, No buffer space available\r\nDone 262154\r\n```","author":{"url":"https://github.com/MrSonicMaster","@type":"Person","name":"MrSonicMaster"},"datePublished":"2022-10-14T19:49:07.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/702/f-stack/issues/702"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7506ad5a-4ccc-8ca6-b43a-189482df1d54 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E674:406C5:2B3E6A:3AABAE:69695A2B |
| html-safe-nonce | a061af41b15ecd9c537d422d3ff9a64982227726f9acbb9a2c39694bb6c69927 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjc0OjQwNkM1OjJCM0U2QTozQUFCQUU6Njk2OTVBMkIiLCJ2aXNpdG9yX2lkIjoiNDA0MTY1MTMzMzUzNjI0MjIxOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8ff0c27b08375ce225f76bc48f79d4c65436fda062c720887e43006c971d36ce |
| hovercard-subject-tag | issue:1409783971 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/F-Stack/f-stack/702/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c3b35c4fc95244aba4678ce28dc1f9fd98bae8797adc9d066a47a98144f1be11/F-Stack/f-stack/issues/702 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c3b35c4fc95244aba4678ce28dc1f9fd98bae8797adc9d066a47a98144f1be11/F-Stack/f-stack/issues/702 |
| og:image:alt | My application suddenly start spamming ff_socket: "No buffer space available." so I went to debug why. I figured out that setting tcp stack back to default freebsd stack solved the issue, it only h... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | MrSonicMaster |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9db5f28da7e24035385d7f349f17890cbe016a939ddd7952be0f07b862094f5a |
| turbo-cache-control | no-preview |
| go-import | github.com/F-Stack/f-stack git https://github.com/F-Stack/f-stack.git |
| octolytics-dimension-user_id | 26062241 |
| octolytics-dimension-user_login | F-Stack |
| octolytics-dimension-repository_id | 88224621 |
| octolytics-dimension-repository_nwo | F-Stack/f-stack |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 88224621 |
| octolytics-dimension-repository_network_root_nwo | F-Stack/f-stack |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4e59fe66217d3c72925af2a341ae3a8f2b5b5b2a |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width