Skip to content

Memory leak: New subtensor connection created on each weight setting instead of reusing existing one #61

@rusvo

Description

@rusvo

Description

In bettensor/validator/utils/scoring/weights_functions.py, a new subtensor connection is created every time weights are set:

weights_subtensor = bt.subtensor(network=self.neuron_config.network)This causes:

  • WebSocket connection leaks (connections not properly closed)
  • Memory leak (each connection holds buffers)
  • "Task was destroyed but it is pending!" warnings in async-substrate-interface
  • High memory usage over time (observed 2.4GB+ on validator)

Suggested Fix

Reuse the existing subtensor connection:

weights_subtensor = self.subtensor## Environment

  • bettensor version: main branch (commit fbcb055)
  • async-substrate-interface: 1.5.9
  • Python: 3.x
  • OS: Ubuntu

Additional Context

There may be other places in the codebase with similar issues where bt.subtensor() is called instead of reusing an existing connection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions