RainyXeon / Rainlink

Another lavalink wrapper but focus on stability and rich features
https://rainlinkjs.vercel.app
GNU General Public License v3.0
17 stars 6 forks source link

(Bug): Issue with lavalink connection #66

Closed adh319 closed 2 months ago

adh319 commented 2 months ago

Describe the bug It seems that when we set up 2 or more different Lavalink servers, instead of connecting to all of them, it only connects to one. Even though the console logs multiple connections (one for each Lavalink), it repeatedly connects to the same Lavalink server.

To Reproduce

Expected behavior

Screenshots Console logs screenshot

Additional context

Versions v1.0.7

RainyXeon commented 2 months ago

Can u try to console log the node in ready event and send log here?

adh319 commented 2 months ago
<ref *2> RainlinkNode {
  online: true,
  retryCounter: 0,
  state: 0,
  sudoDisconnect: false,
  manager: <ref *1> Rainlink {
    _events: [Object: null prototype] {
      playerCreate: [Array],
      playerDestroy: [Array],
      nodeClose: [Function (anonymous)],
      nodeConnect: [Function (anonymous)],
      nodeDisconnect: [Function (anonymous)],
      nodeError: [Function (anonymous)],
      nodeReconnect: [Function (anonymous)],
      PlayerException: [Function (anonymous)],
      queueEmpty: [Function (anonymous)],
      trackEnd: [Function (anonymous)],
      trackResolveError: [Function (anonymous)],
      trackStart: [Function (anonymous)],
      trackStuck: [Function (anonymous)]
    },
    _eventsCount: 13,
    _maxListeners: undefined,
    shardCount: 1,
    library: DiscordJS { client: [MainClient], manager: [Circular *1] },
    drivers: [ [Lavalink3], [Nodelink2], [Lavalink4], [FrequenC] ],
    rainlinkOptions: {
      options: [Object],
      library: [DiscordJS],
      nodes: [Array],
      plugins: [Array]
    },
    nodes: RainlinkNodeManager { cache: [Object], manager: [Circular *1] },
    players: RainlinkPlayerManager { cache: {}, manager: [Circular *1] },
    searchEngines: RainlinkDatabase { cache: [Object] },
    searchPlugins: RainlinkDatabase { cache: [Object] },
    plugins: RainlinkDatabase { cache: [Object] },
    search: [Function: bound search],
    id: '1056163726648164413',
    [Symbol(shapeMode)]: false,
    [Symbol(kCapture)]: false
  },
  options: {
    name: 'Lunox 2',
    host: 'lava-v4.ajieblogs.eu.org',
    port: 80,
    auth: 'https://dsc.gg/ajidevserver',
    secure: false,
    driver: 'lavalink/v4/koinu'
  },
  driver: Lavalink4 {
    id: 'lavalink/v4/koinu',
    wsUrl: 'ws://lava-v4.ajieblogs.eu.org:80/v4/websocket',
    httpUrl: 'http://lava-v4.ajieblogs.eu.org:80/v4',
    manager: <ref *1> Rainlink {
      _events: [Object: null prototype],
      _eventsCount: 13,
      _maxListeners: undefined,
      shardCount: 1,
      library: [DiscordJS],
      drivers: [Array],
      rainlinkOptions: [Object],
      nodes: [RainlinkNodeManager],
      players: [RainlinkPlayerManager],
      searchEngines: [RainlinkDatabase],
      searchPlugins: [RainlinkDatabase],
      plugins: [RainlinkDatabase],
      search: [Function: bound search],
      id: '1056163726648164413',
      [Symbol(shapeMode)]: false,
      [Symbol(kCapture)]: false
    },
    node: [Circular *2],
    playerFunctions: RainlinkDatabase { cache: {} },
    functions: RainlinkDatabase { cache: [Object] },
    sessionId: null,
    wsClient: RainlinkWebsocket {
      _events: [Object: null prototype],
      _eventsCount: 4,
      _maxListeners: undefined,
      url: 'ws://lava-v4.ajieblogs.eu.org:80/v4/websocket',
      options: [Object],
      socket: null,
      continueInfo: [Object],
      state: 'WAITING',
      [Symbol(shapeMode)]: false,
      [Symbol(kCapture)]: false
    }
  },
  rest: RainlinkRest {
    manager: <ref *1> Rainlink {
      _events: [Object: null prototype],
      _eventsCount: 13,
      _maxListeners: undefined,
      shardCount: 1,
      library: [DiscordJS],
      drivers: [Array],
      rainlinkOptions: [Object],
      nodes: [RainlinkNodeManager],
      players: [RainlinkPlayerManager],
      searchEngines: [RainlinkDatabase],
      searchPlugins: [RainlinkDatabase],
      plugins: [RainlinkDatabase],
      search: [Function: bound search],
      id: '1056163726648164413',
      [Symbol(shapeMode)]: false,
      [Symbol(kCapture)]: false
    },
    options: {
      name: 'Lunox 2',
      host: 'lava-v4.ajieblogs.eu.org',
      port: 80,
      auth: 'https://dsc.gg/ajidevserver',
      secure: false,
      driver: 'lavalink/v4/koinu'
    },
    nodeManager: [Circular *2],
    sessionId: ''
  },
  wsEvent: RainlinkPlayerEvents {
    methods: {
      TrackStartEvent: [Function: TrackStartEvent],
      TrackEndEvent: [Function: TrackEndEvent],
      TrackExceptionEvent: [Function: TrackExceptionEvent],
      TrackStuckEvent: [Function: TrackStuckEvent],
      WebSocketClosedEvent: [Function: WebSocketClosedEvent]
    }
  },
  stats: {
    players: 0,
    playingPlayers: 0,
    uptime: 0,
    memory: { free: 0, used: 0, allocated: 0, reservable: 0 },
    cpu: { cores: 0, systemLoad: 0, lavalinkLoad: 0 },
    frameStats: { sent: 0, nulled: 0, deficit: 0 }
  }
}
<ref *2> RainlinkNode {
  online: true,
  retryCounter: 0,
  state: 0,
  sudoDisconnect: false,
  manager: <ref *1> Rainlink {
    _events: [Object: null prototype] {
      playerCreate: [Array],
      playerDestroy: [Array],
      nodeClose: [Function (anonymous)],
      nodeConnect: [Function (anonymous)],
      nodeDisconnect: [Function (anonymous)],
      nodeError: [Function (anonymous)],
      nodeReconnect: [Function (anonymous)],
      PlayerException: [Function (anonymous)],
      queueEmpty: [Function (anonymous)],
      trackEnd: [Function (anonymous)],
      trackResolveError: [Function (anonymous)],
      trackStart: [Function (anonymous)],
      trackStuck: [Function (anonymous)]
    },
    _eventsCount: 13,
    _maxListeners: undefined,
    shardCount: 1,
    library: DiscordJS { client: [MainClient], manager: [Circular *1] },
    drivers: [ [Lavalink3], [Nodelink2], [Lavalink4], [FrequenC] ],
    rainlinkOptions: {
      options: [Object],
      library: [DiscordJS],
      nodes: [Array],
      plugins: [Array]
    },
    nodes: RainlinkNodeManager { cache: [Object], manager: [Circular *1] },
    players: RainlinkPlayerManager { cache: {}, manager: [Circular *1] },
    searchEngines: RainlinkDatabase { cache: [Object] },
    searchPlugins: RainlinkDatabase { cache: [Object] },
    plugins: RainlinkDatabase { cache: [Object] },
    search: [Function: bound search],
    id: '1056163726648164413',
    [Symbol(shapeMode)]: false,
    [Symbol(kCapture)]: false
  },
  options: {
    name: 'Lunox 2',
    host: 'lava-v4.ajieblogs.eu.org',
    port: 80,
    auth: 'https://dsc.gg/ajidevserver',
    secure: false,
    driver: 'lavalink/v4/koinu'
  },
  driver: Lavalink4 {
    id: 'lavalink/v4/koinu',
    wsUrl: 'ws://lava-v4.ajieblogs.eu.org:80/v4/websocket',
    httpUrl: 'http://lava-v4.ajieblogs.eu.org:80/v4',
    manager: <ref *1> Rainlink {
      _events: [Object: null prototype],
      _eventsCount: 13,
      _maxListeners: undefined,
      shardCount: 1,
      library: [DiscordJS],
      drivers: [Array],
      rainlinkOptions: [Object],
      nodes: [RainlinkNodeManager],
      players: [RainlinkPlayerManager],
      searchEngines: [RainlinkDatabase],
      searchPlugins: [RainlinkDatabase],
      plugins: [RainlinkDatabase],
      search: [Function: bound search],
      id: '1056163726648164413',
      [Symbol(shapeMode)]: false,
      [Symbol(kCapture)]: false
    },
    node: [Circular *2],
    playerFunctions: RainlinkDatabase { cache: {} },
    functions: RainlinkDatabase { cache: [Object] },
    sessionId: 'dlneykfqlucth289',
    wsClient: RainlinkWebsocket {
      _events: [Object: null prototype],
      _eventsCount: 4,
      _maxListeners: undefined,
      url: 'ws://lava-v4.ajieblogs.eu.org:80/v4/websocket',
      options: [Object],
      socket: [Socket],
      continueInfo: [Object],
      state: 'WAITING',
      [Symbol(shapeMode)]: false,
      [Symbol(kCapture)]: false
    }
  },
  rest: RainlinkRest {
    manager: <ref *1> Rainlink {
      _events: [Object: null prototype],
      _eventsCount: 13,
      _maxListeners: undefined,
      shardCount: 1,
      library: [DiscordJS],
      drivers: [Array],
      rainlinkOptions: [Object],
      nodes: [RainlinkNodeManager],
      players: [RainlinkPlayerManager],
      searchEngines: [RainlinkDatabase],
      searchPlugins: [RainlinkDatabase],
      plugins: [RainlinkDatabase],
      search: [Function: bound search],
      id: '1056163726648164413',
      [Symbol(shapeMode)]: false,
      [Symbol(kCapture)]: false
    },
    options: {
      name: 'Lunox 2',
      host: 'lava-v4.ajieblogs.eu.org',
      port: 80,
      auth: 'https://dsc.gg/ajidevserver',
      secure: false,
      driver: 'lavalink/v4/koinu'
    },
    nodeManager: [Circular *2],
    sessionId: 'dlneykfqlucth289'
  },
  wsEvent: RainlinkPlayerEvents {
    methods: {
      TrackStartEvent: [Function: TrackStartEvent],
      TrackEndEvent: [Function: TrackEndEvent],
      TrackExceptionEvent: [Function: TrackExceptionEvent],
      TrackStuckEvent: [Function: TrackStuckEvent],
      WebSocketClosedEvent: [Function: WebSocketClosedEvent]
    }
  },
  stats: {
    players: 2,
    playingPlayers: 0,
    uptime: 491222844,
    memory: {
      free: 106052792,
      used: 233685832,
      allocated: 339738624,
      reservable: 4192206848
    },
    cpu: {
      cores: 6,
      systemLoad: 0.003801765105227427,
      lavalinkLoad: 0.0009502090459901179
    },
    frameStats: { sent: 0, nulled: 0, deficit: 0 }
  }
}
adh319 commented 2 months ago

i have put 2 different lavalink in node options. but only the second one is loaded and loaded twice. the first one is not loaded or connected

lavalink 1: Screenshot lavalink 2: Screenshot

RainyXeon commented 2 months ago

I tried and can't reproduce. Can u try to console.log the varible where u pass the node list?

[Rainlink] | Finished the initialization process | Registered 0 plugins | Now connect all current nodes
[Rainlink] / [Node @ owo1] | No driver was found, using lavalink v4 driver instead
[Rainlink] / [NodeManager] | Node owo1 added to manager!
[Rainlink] / [Node @ owo2] | No driver was found, using lavalink v4 driver instead
[Rainlink] / [NodeManager] | Node owo2 added to manager!
Dreamtest#6494 Ready!
[Rainlink] / [Node @ owo2] | Node connected! URL: ws://node.lewdhutao.my.eu.org:80/v4/websocket
Lavalink owo2: Ready!
{
  name: 'owo2',
  host: 'node.lewdhutao.my.eu.org',
  port: 80,
  auth: 'youshallnotpass',
  secure: false
}
[Rainlink] / [Node @ owo1] | Node connected! URL: ws://lavalink.jompo.cloud:2333/v4/websocket
Lavalink owo1: Ready!
{
  name: 'owo1',
  host: 'lavalink.jompo.cloud',
  port: 2333,
  auth: 'jompo',
  secure: false
}
[
  {
    node: {
      name: 'owo1',
      host: 'lavalink.jompo.cloud',
      port: 2333,
      auth: 'jompo',
      secure: false
    },
    stats: {
      players: 5,
      playingPlayers: 0,
      uptime: 518062757,
      memory: [Object],
      cpu: [Object],
      frameStats: [Object]
    }
  },
  {
    node: {
      name: 'owo2',
      host: 'node.lewdhutao.my.eu.org',
      port: 80,
      auth: 'youshallnotpass',
      secure: false
    },
    stats: {
      players: 50,
      playingPlayers: 5,
      uptime: 1464359725,
      memory: [Object],
      cpu: [Object],
      frameStats: [Object]
    }
  }
]
adh319 commented 2 months ago

the varible where u pass the node list?

i dont get what you mean, but...

so this is my actual code in nodeConnect event

module.exports = async (client, node) => {
    console.log(`[INFO] Node ${node.options.name} ready`);
}

and this in my node configuration list looks like

rainlinkNodes: [
    {
        name: process.env.NODE_NAME1,
        host: process.env.NODE_HOST1,
        port: parseInt(process.env.NODE_PORT1),
        auth: process.env.NODE_AUTH1,
        secure: parseBoolean(process.env.NODE_SECURE1),
        driver: process.env.NODE_DRIVER1,
    },
    {
        name: process.env.NODE_NAME2,
        host: process.env.NODE_HOST2,
        port: parseInt(process.env.NODE_PORT2),
        auth: process.env.NODE_AUTH2,
        secure: parseBoolean(process.env.NODE_SECURE2),
        driver: process.env.NODE_DRIVER2,
    },
];
adh319 commented 2 months ago

I tried and can't reproduce. Can u try to console.log the varible where u pass the node list?

[Rainlink] | Finished the initialization process | Registered 0 plugins | Now connect all current nodes
[Rainlink] / [Node @ owo1] | No driver was found, using lavalink v4 driver instead
[Rainlink] / [NodeManager] | Node owo1 added to manager!
[Rainlink] / [Node @ owo2] | No driver was found, using lavalink v4 driver instead
[Rainlink] / [NodeManager] | Node owo2 added to manager!
Dreamtest#6494 Ready!
[Rainlink] / [Node @ owo2] | Node connected! URL: ws://node.lewdhutao.my.eu.org:80/v4/websocket
Lavalink owo2: Ready!
{
  name: 'owo2',
  host: 'node.lewdhutao.my.eu.org',
  port: 80,
  auth: 'youshallnotpass',
  secure: false
}
[Rainlink] / [Node @ owo1] | Node connected! URL: ws://lavalink.jompo.cloud:2333/v4/websocket
Lavalink owo1: Ready!
{
  name: 'owo1',
  host: 'lavalink.jompo.cloud',
  port: 2333,
  auth: 'jompo',
  secure: false
}
[
  {
    node: {
      name: 'owo1',
      host: 'lavalink.jompo.cloud',
      port: 2333,
      auth: 'jompo',
      secure: false
    },
    stats: {
      players: 5,
      playingPlayers: 0,
      uptime: 518062757,
      memory: [Object],
      cpu: [Object],
      frameStats: [Object]
    }
  },
  {
    node: {
      name: 'owo2',
      host: 'node.lewdhutao.my.eu.org',
      port: 80,
      auth: 'youshallnotpass',
      secure: false
    },
    stats: {
      players: 50,
      playingPlayers: 5,
      uptime: 1464359725,
      memory: [Object],
      cpu: [Object],
      frameStats: [Object]
    }
  }
]

I found where the problem was coming from—it's related to the driver options of Lavalink. I had set the same driver option value for each Lavalink instance since all my Lavalink servers are v4. I thought I needed to include the driver options for them, but once I removed all the driver options, it worked and the issue was fixed.

Limeamir commented 2 months ago

Hi adh

adh319 commented 2 months ago

Hi adh

hello?

RainyXeon commented 2 months ago

Ah, make sense. I will try that anyways