简体   繁体   English

在Vue.js服务器端渲染中跟踪内存泄漏?

[英]Tracking down memory leak in Vue.js server-side rendering?

We've got a Vue.js (v2.2.6) app running in production with server-side rendering based on the Hacker News demo app structure . 我们有一个Vue.js(v2.2.6)应用程序在生产中运行,基于Hacker News演示应用程序结构进行服务器端渲染。 We've got a memory leak that causes the process to run out of memory and crash after around 6-12 hours, and we've started taking heap snapshots on the server to try and track the issue. 我们有一个内存泄漏导致进程耗尽内存并在大约6-12小时后崩溃,我们已经开始在服务器上获取堆快照以尝试跟踪问题。

However, we've been digging through these for days and haven't really gotten anywhere. 然而,我们已经挖掘了这些好几天,并没有真正得到任何地方。 The thing that sticks out (as you can see in the below screenshot) is that there are many instances of VueComponent and Vue$2 being created and never deleted from memory. 突出的东西(正如你在下面的截图中看到的)是有很多VueComponentVue$2实例被创建并且永远不会从内存中删除。 I don't know enough about the internals of Vue's server-side rendering to know if this is a real lead and where to look from there if it is. 我对Vue服务器端渲染的内部结构知之甚少,不知道这是否是一个真正的领导者,如果是的话,从哪里可以看到。

在此输入图像描述 在此输入图像描述

Has anyone run into something like this or have any ideas where we might look to determine what could be causing this? 有没有人碰到这样的事情,或者有什么想法,我们可能会找出可能导致这种情况的原因?

I finally tracked this down by switching to a more powerful debugging tool than using heap snapshots alone: LLDB and the llnode plugin. 我最终通过切换到比单独使用堆快照更强大的调试工具来跟踪这个问题:LLDB和llnode插件。 This should be very familiar if you have used Joyent's SmartOS and mdb, and it gives you a lot more data to drill into than the standard heap snapshot. 如果您使用了Joyent的SmartOS和mdb,这应该是非常熟悉的,并且它比标准堆快照提供了更多的钻取数据。

I used the dumpme node module to trigger a core dump inside my production application (there are other ways of doing this, but I found this easiest). 我使用dumpme节点模块在我的生产应用程序中触发核心转储(还有其他方法可以做到这一点,但我发现这是最容易的)。

I then followed the instructions found at https://developer.ibm.com/node/2016/09/27/advances-in-core-dump-debugging-for-node-js/ and started tracing the references to the VueComponents that were being held in memory. 然后,我按照https://developer.ibm.com/node/2016/09/27/advances-in-core-dump-debugging-for-node-js/上的说明进行操作,并开始跟踪对VueComponents的引用被关在记忆中。

> lldb node -c core
(lldb) plugin load ./node_modules/llnode/llnode.so
(lldb) v8 findjsobjects
(lldb) v8 findjsinstances VueComponent
(lldb) v8 inspect ...

In this case, it turned out that there was a recursive setTimeout that was never getting cleared when the component was destroyed, so the reference to the entire application stayed in memory. 在这种情况下,事实证明有一个递归的setTimeout在组件被销毁时永远不会被清除,因此对整个应用程序的引用保留在内存中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM