René's URL Explorer Experiment


Title: AMQP reconnections don't clean up `sync-out` event handlers, causing memory leaks · Issue #202 · feathersjs/feathers-sync · GitHub

Open Graph Title: AMQP reconnections don't clean up `sync-out` event handlers, causing memory leaks · Issue #202 · feathersjs/feathers-sync

X Title: AMQP reconnections don't clean up `sync-out` event handlers, causing memory leaks · Issue #202 · feathersjs/feathers-sync

Description: Background I just had a deep dive into some memory issues of our application. It kept growing over time and we couldn't pinpoint what was causing it. Eventually we saw thousands of references of 131 kB to an instance of Mux from amqplib ...

Open Graph Description: Background I just had a deep dive into some memory issues of our application. It kept growing over time and we couldn't pinpoint what was causing it. Eventually we saw thousands of references of 13...

X Description: Background I just had a deep dive into some memory issues of our application. It kept growing over time and we couldn't pinpoint what was causing it. Eventually we saw thousands of references o...

Opengraph URL: https://github.com/feathersjs/feathers-sync/issues/202

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"AMQP reconnections don't clean up `sync-out` event handlers, causing memory leaks","articleBody":"### Background\n\nI just had a deep dive into some memory issues of our application. It kept growing over time and we couldn't pinpoint what was causing it. Eventually we saw thousands of references of 131 kB to an instance of `Mux` from `amqplib` (amounting to ~2.1GB of unnecessary memory). This led led us to `feathers-sync`, as we use it with the AMQP adapter.\n\n#### Update 2025-09-25\nSee my [comment](https://github.com/feathersjs/feathers-sync/issues/202#issuecomment-3258000655) below\n\n### Issue\n\nThe AMQP adapter doesn't properly clean up the registered `app.on('sync-out', handlerFn)` event handler when a channel is closed. The `handlerFn` contains a reference to the `channel` which is never cleaned up, as the event listener stays active even after a connection is closed.\n\nThe AMQP adapter uses `amqp-connection-manager` for automatic reconnections. The `setup` option of `createChannel` ([related feathers-sync code](https://github.com/feathersjs/feathers-sync/blob/b778f03ebff718b4f3b27e8167c5c8c6be5837ec/lib/adapters/amqp.js#L16-L56)) is called each time a new connection is made. \n`feathers-sync` sets up an event listener to `sync-out` to publish the event to the queue within that `setup` function. However, in the event of a channel closing (due to whatever reason), the event listener is never cleaned up. Upon new events it'll keep executing the now redundant event listener, as the channel can't be published to anymore.\n\nSee the below image for an example of the issue. I added some debug logs to illustrate when a channel is reconnected / closed, as well as which events are sent on which pid / channel. For this I also had to make a small change in `amqplib` to attach a random string to each created channel.\n\nScenario: I make a change to an item, wait for the event to be sent, and then I restart my AMQP Docker container to trigger a reconnection.\n\n\u003cimg width=\"593\" height=\"486\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/a1956dd4-f13e-49e6-8fc4-5c11a9547646\" /\u003e\n\n### Impact\n \n* Memory leaks\n  * The `channel` reference (and all other references within it) stay in memory\n* Unnecessary processing, as it'll keep trying to call `channel.publish` on a closed channel, which will just error\n\n### Reproduction\n\n1. Setup a Docker container with AMQP (or run it locally)\n2. Run a Feathers app with the AMQP adapter for `feathers-sync` using `DEBUG=feathers-sync:amqp` for debug logs\n3. Trigger something that causes events to be sent via `feathers-sync`\n4. Observe how only one \"Publish success: |true|\" debug is logged\n5. Restart AMQP\n6. Trigger the same thing again\n7. Observe how there is now also a \"Publish fail: |Channel closed|\" log alongside the \"Publish success: |true|\" log\n8. Repeat however many times as you want. Each restart of AMQP will add another \"Publish fail: |Channel closed|\" log\n\n### Proposed solution\n\nUnregister the event listener when a channel is closed. From what I can gather, you can listen to `close` events on the channel itself. The following seems to fix it for me:\n\n```diff\n-          // Publish the received message to the queue\n-          app.on('sync-out', (data) =\u003e {\n-            try {\n-              const publishResponse = channel.publish(\n-                key,\n-                queue,\n-                Buffer.from(data)\n-              )\n-              debug(`Publish success: |${publishResponse}| APMQ channel`)\n-           } catch (error) {\n-              debug(`Publish fail: |${error.message}| APMQ channel`)\n-           }\n-          })\n\n+         function publishToQueue(data) {\n+           try {\n+              const publishResponse = channel.publish(\n+                key,\n+                queue,\n+                Buffer.from(data)\n+              )\n+              debug(`Publish success: |${publishResponse}| APMQ channel`)\n+            } catch (error) {\n+              debug(`Publish fail: |${error.message}| APMQ channel`)\n+            }\n+          }\n\n+          // Publish the received message to the queue\n+          app.on('sync-out', publishToQueue)\n\n+          channel.on('close', () =\u003e {\n+            debug(Channel closed')\n+            app.off('sync-out', publishToQueue)\n+          })\n+        })\n```\n\nSide note: all the debug logs in the AMQP adapter have a typo: `APMQ` should be `AMQP`","author":{"url":"https://github.com/JulienZD","@type":"Person","name":"JulienZD"},"datePublished":"2025-08-26T10:37:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/202/feathers-sync/issues/202"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:9a62db7a-738c-ba14-c71b-4811bb4b3df1
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id93D2:FC3F2:9822398:C967FDC:696E034B
html-safe-noncee407ba419493d42275f7fa32dd4babb5c046654ed2efb46b1d7f00ffe2cc5abf
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0QyOkZDM0YyOjk4MjIzOTg6Qzk2N0ZEQzo2OTZFMDM0QiIsInZpc2l0b3JfaWQiOiI2ODAzMjA1MDQwMTY5MTU3NDUyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac6d77bbbbe3d6ee30ded235fbf91b3204245f8f185dc63e7b8a45cde11fa8ed10
hovercard-subject-tagissue:3355098468
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/feathersjs/feathers-sync/202/issue_layout
twitter:imagehttps://opengraph.githubassets.com/82d36c27b142a04253f3b4657357c1ec940b1ee5952fc6448105921e2cdfa453/feathersjs/feathers-sync/issues/202
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/82d36c27b142a04253f3b4657357c1ec940b1ee5952fc6448105921e2cdfa453/feathersjs/feathers-sync/issues/202
og:image:altBackground I just had a deep dive into some memory issues of our application. It kept growing over time and we couldn't pinpoint what was causing it. Eventually we saw thousands of references of 13...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameJulienZD
hostnamegithub.com
expected-hostnamegithub.com
None9b5131b207ddd175abf059a848d5f4302ec0606b02211b989013be49cf08593e
turbo-cache-controlno-preview
go-importgithub.com/feathersjs/feathers-sync git https://github.com/feathersjs/feathers-sync.git
octolytics-dimension-user_id5321853
octolytics-dimension-user_loginfeathersjs
octolytics-dimension-repository_id32042756
octolytics-dimension-repository_nwofeathersjs/feathers-sync
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id32042756
octolytics-dimension-repository_network_root_nwofeathersjs/feathers-sync
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasef8590a63bfc8093b241930ca57d536c9a50f9680
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/feathersjs/feathers-sync/issues/202#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffeathersjs%2Ffeathers-sync%2Fissues%2F202
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffeathersjs%2Ffeathers-sync%2Fissues%2F202
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=feathersjs%2Ffeathers-sync
Reloadhttps://patch-diff.githubusercontent.com/feathersjs/feathers-sync/issues/202
Reloadhttps://patch-diff.githubusercontent.com/feathersjs/feathers-sync/issues/202
Reloadhttps://patch-diff.githubusercontent.com/feathersjs/feathers-sync/issues/202
feathersjs https://patch-diff.githubusercontent.com/feathersjs
feathers-synchttps://patch-diff.githubusercontent.com/feathersjs/feathers-sync
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Ffeathersjs%2Ffeathers-sync
Fork 41 https://patch-diff.githubusercontent.com/login?return_to=%2Ffeathersjs%2Ffeathers-sync
Star 223 https://patch-diff.githubusercontent.com/login?return_to=%2Ffeathersjs%2Ffeathers-sync
Code https://patch-diff.githubusercontent.com/feathersjs/feathers-sync
Issues 6 https://patch-diff.githubusercontent.com/feathersjs/feathers-sync/issues
Pull requests 3 https://patch-diff.githubusercontent.com/feathersjs/feathers-sync/pulls
Actions https://patch-diff.githubusercontent.com/feathersjs/feathers-sync/actions
Security Uh oh! There was an error while loading. Please reload this page. https://patch-diff.githubusercontent.com/feathersjs/feathers-sync/security
Please reload this pagehttps://patch-diff.githubusercontent.com/feathersjs/feathers-sync/issues/202
Insights https://patch-diff.githubusercontent.com/feathersjs/feathers-sync/pulse
Code https://patch-diff.githubusercontent.com/feathersjs/feathers-sync
Issues https://patch-diff.githubusercontent.com/feathersjs/feathers-sync/issues
Pull requests https://patch-diff.githubusercontent.com/feathersjs/feathers-sync/pulls
Actions https://patch-diff.githubusercontent.com/feathersjs/feathers-sync/actions
Security https://patch-diff.githubusercontent.com/feathersjs/feathers-sync/security
Insights https://patch-diff.githubusercontent.com/feathersjs/feathers-sync/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/feathersjs/feathers-sync/issues/202
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/feathersjs/feathers-sync/issues/202
#203https://github.com/feathersjs/feathers-sync/pull/203
AMQP reconnections don't clean up sync-out event handlers, causing memory leakshttps://patch-diff.githubusercontent.com/feathersjs/feathers-sync/issues/202#top
#203https://github.com/feathersjs/feathers-sync/pull/203
https://github.com/JulienZD
https://github.com/JulienZD
JulienZDhttps://github.com/JulienZD
on Aug 26, 2025https://github.com/feathersjs/feathers-sync/issues/202#issue-3355098468
commenthttps://github.com/feathersjs/feathers-sync/issues/202#issuecomment-3258000655
related feathers-sync codehttps://github.com/feathersjs/feathers-sync/blob/b778f03ebff718b4f3b27e8167c5c8c6be5837ec/lib/adapters/amqp.js#L16-L56
https://private-user-images.githubusercontent.com/48630731/482056212-a1956dd4-f13e-49e6-8fc4-5c11a9547646.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Njg4MTc3ODQsIm5iZiI6MTc2ODgxNzQ4NCwicGF0aCI6Ii80ODYzMDczMS80ODIwNTYyMTItYTE5NTZkZDQtZjEzZS00OWU2LThmYzQtNWMxMWE5NTQ3NjQ2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAxMTklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMTE5VDEwMTEyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWEwODkyNjI3N2JjNGI0MmMxN2Q1OWZkMGUwN2QzMmE2NTdjY2FmNDY3NTk3NGQ3YWQzNTZhN2Q5NjhjNTE1ODcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.E_XAYzySbRcx4O2uv9OMkjO1U0B7Xy7a95ajMO4LUp8
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.