-
Notifications
You must be signed in to change notification settings - Fork 567
Open
Description
Description
The Client class has a bug where event listeners accumulate on each reconnection, causing the 'connected' event to fire multiple times (N+1 pattern) after each reconnect.
This issue was originally reported on Discord by a developer building a ConnectionManager class.
Steps to Reproduce
- Create a
Clientinstance and add a'connected'event listener - Connect to an XRPL server
- Simulate network disconnect (e.g., close WebSocket or toggle WiFi)
- Wait for automatic reconnection
- Repeat steps 3-4 multiple times
Expected behavior:
The 'connected' event should fire exactly once per connection/reconnection.
Actual behavior:
- 1st reconnect:
'connected'fires 1 time ✓ - 2nd reconnect:
'connected'fires 2 times ❌ - 3rd reconnect:
'connected'fires 3 times ❌ - 4th reconnect:
'connected'fires 4 times ❌ - And so on (N+1 pattern)
Example Code
const { Client } = require('xrpl');
class ConnectionManager {
constructor() {
this.client = new Client('wss://s.altnet.rippletest.net:51233');
this.client.on('connected', () => {
console.log('Connected to XRPL');
// This will be called multiple times after each reconnection
});
}
async connect() {
await this.client.connect();
}
}
const manager = new ConnectionManager();
await manager.connect();
// Disconnect WiFi, then reconnect
// First time: "Connected to XRPL" appears once ✓
// Second time: "Connected to XRPL" appears twice ❌
// Third time: "Connected to XRPL" appears three times ❌Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels