optimizely / optimizely/javascript-sdk

[BUG] Memory leak when migrating from v5 to v6

Abierto
#1,138 9 comentarios 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

acknowledged bug needs-triage
Lenguaje dominante
TypeScript
Estrellas
82
Forks
86
Merge medio
2 d 15 h
PR fusionados (30 d)
3

Descripción

Is there an existing issue for this?
  • I have searched the existing issues
SDK Version

6.3.1

Current Behavior

Memory increases over time and is not garbage collected

Expected Behavior

Memory is like it was before

Steps To Reproduce

We rewrote the optimizely instance creation from:

const DEFAULT_DATAFILE_OPTIONS = {
  autoUpdate: true,
  updateInterval: 5 * 60 * 1000 // 5 minutes
}

const DEFAULT_EVENTS_OPTIONS = {
  batchSize: 10,
  flushInterval: 1000
}

const DEFAULT_TIMEOUT = 500

const LOGGER_LEVEL = process.env.NODE_ENV === 'production' ? ERROR : INFO

export default class OptimizelyAdapter {
  static createOptimizelyInstance({
    options: optionParameter,
    sdkKey,
    datafile,
    optimizely = optimizelySDK,
    eventDispatcher = optimizelySDK.eventDispatcher
  }) {
    const options = {...DEFAULT_DATAFILE_OPTIONS, ...optionParameter}
    optimizely.setLogLevel(LOGGER_LEVEL)
    optimizely.setLogger(optimizely.logging.createLogger())
    if (!datafile && typeof window !== 'undefined' && window.__INITIAL_CONTEXT_VALUE__?.pde) {
      datafile = window.__INITIAL_CONTEXT_VALUE__.pde
      sdkKey = undefined
    }

    const isServer = typeof window === 'undefined'
    const optimizelyInstance = optimizely.createInstance({
      sdkKey,
      datafileOptions: options,
      datafile,
      eventDispatcher,
      ...DEFAULT_EVENTS_OPTIONS,
      defaultDecideOptions: isServer ? [optimizely.OptimizelyDecideOption.DISABLE_DECISION_EVENT] : []
    })

    return optimizelyInstance
  }
}

To:

const DEFAULT_DATAFILE_OPTIONS = {
  autoUpdate: true,
  updateInterval: 5 * 60 * 1000 // 5 minutes
}

const DEFAULT_EVENTS_OPTIONS = {
  batchSize: 10,
  flushInterval: 1000
}

const DEFAULT_TIMEOUT = 500

const LOGGER_LEVEL = process.env.NODE_ENV === 'production' ? ERROR : INFO

export default class OptimizelyAdapter {
  static createOptimizelyInstance({options: optionParameter, sdkKey, datafile}) {
    if (!datafile && typeof window !== 'undefined' && window.__INITIAL_CONTEXT_VALUE__?.pde) {
      datafile = window.__INITIAL_CONTEXT_VALUE__.pde
      sdkKey = undefined
    }

    const isServer = typeof window === 'undefined'

    const projectConfigManager = sdkKey
      ? createPollingProjectConfigManager({sdkKey, datafile, ...DEFAULT_DATAFILE_OPTIONS, ...optionParameter})
      : createStaticProjectConfigManager({datafile})

    const eventProcessor = createBatchEventProcessor({
      ...DEFAULT_EVENTS_OPTIONS,
      ...optionParameter
    })

    const odpManager = createOdpManager()

    const logger = createLogger({
      level: LOGGER_LEVEL
    })

    return createInstance({
      projectConfigManager,
      eventProcessor,
      odpManager,
      logger,
      defaultDecideOptions: isServer ? [OptimizelyDecideOption.DISABLE_DECISION_EVENT] : []
    })
  }
}

The instance is created in the server during bootstrap and we just create one. We would like to keep the current behaviour as it is (not using the disposable flag). I will try to do some memory snapshots but I was wondering is something is wrong since we only changed this part following your migration from v5 to v6 guide

SDK Type

Browser

Node Version

JS SDK

Browsers impacted

No response

Link

No response

Logs

No response

Severity

No response

Workaround/Solution

No response

Recent Change

No response

Conflicts

No response

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con el cambio de creación de instancias de v5 a v6 mostrado en el issue y reproduce el caso de server-bootstrap que crea una instancia. Compara las instantáneas de memoria a lo largo del tiempo, centrándote en el gestor de configuración del proyecto, el procesador de eventos, el gestor de ODP, el logger y la ruta de createInstance. Se considera completado cuando se haya identificado el origen de la memoria retenida y se haya confirmado un comportamiento estable de la memoria sin habilitar el disposable flag.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript
Área
backend, performance
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
28/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.