captbaritone / raven-for-redux

A Raven middleware for Redux
295 stars 25 forks source link

Running on node-js causes a memory leak #76

Closed rodolfo3 closed 6 years ago

rodolfo3 commented 6 years ago

Setting it up in a running server-side-rendering app causes the memory grows constantly:

screenshot_2018-06-26 node vms - eduk-beta-web-prd a4845384a7b3 - new relic

(it goes down when the server restarts the node process due memory restrictions)

The only difference is that I setup Raven globally:

global.Raven = require('raven');

I do this because I setup differently on client-side.

My store middlewares are:

import { createStore, applyMiddleware, compose } from 'redux';
import createRavenMiddleware from 'raven-for-redux';
import thunk from 'redux-thunk';
import rootReducer from '../reducers';

const composeEnhancers = (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) || compose;

const configureStore = (preloadedState = {}) => createStore(
  rootReducer,
  preloadedState,
  composeEnhancers(
    applyMiddleware(thunk),
    applyMiddleware(createRavenMiddleware(Raven)),
  ),
);

In my packages.json, I have these versions:

    "raven-for-redux": "^1.3.1",
    "react-redux": "^5.0.3",
    "redux": "^3.6.0",
    "redux-thunk": "^2.2.0",

This behavior happens on nodejs 8.9.4 and 10.3.0.

rodolfo3 commented 6 years ago

Is it because it calls Raven.setDataCallback each store creation? The it will create and add a new function to every store creation (with happens a lot on server-side-rendering)

captbaritone commented 6 years ago

Looks like the same issue as this: https://github.com/captbaritone/raven-for-redux/issues/50

This library is not compatible with Node Raven, since Node Raven has a different API. I would suggest you conditionally omit the raven-for-redux middleware when server rendering.