Skip to content

Missing timeout: Binance feed WebSocket — no connection timeout in establishConnection() #253

@realfishsam

Description

@realfishsam

Location

core/src/feeds/binance/binance-feed.ts:153

Code

private establishConnection(): Promise<void> {
    return new Promise((resolve, reject) => {
        const url = this.apiKey
            ? `${this.wsUrl}?key=${this.apiKey}`
            : this.wsUrl;

        const ws = new WebSocket(url);

        ws.on('open', () => {
            this.ws = ws;
            this.connectionPromise = null;
            ws.send(JSON.stringify({ op: 'subscribe_all' }));
            resolve();
        });

Risk

Same pattern as Chainlink feed: the connection promise has no timeout. If the Binance WebSocket endpoint hangs (no open, no error), the promise never settles and all Binance price feed data subscriptions block indefinitely.

Affected Methods

  • BinanceFeed.connect()establishConnection()
  • All Binance price feed subscriptions and data consumers

Suggested Fix

const timeout = setTimeout(() => {
    ws.terminate();
    reject(new Error('Binance WebSocket connection timeout'));
}, 15_000);

ws.on('open', () => { clearTimeout(timeout); /* ... */ resolve(); });
ws.on('error', (err) => { clearTimeout(timeout); reject(err); });

Found by automated missing timeout audit

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions