Skip to content

[non-null] gemini-titan/websocket.ts: 2 unsafe Map.get()! assertions on resolver maps #235

@realfishsam

Description

@realfishsam

Risk Level

HIGH

File

core/src/exchanges/gemini-titan/websocket.ts

Findings

  • Line 276: this.orderBookResolvers.get(symbol)!.push({ resolve, reject }); — assumes symbol key exists in orderBookResolvers; crashes if it does not.
  • Line 305: this.tradeResolvers.get(symbol)!.push({ resolve, reject }); — same pattern on tradeResolvers.

What Happens When It's Wrong

TypeError: Cannot read properties of undefined (reading 'push') — the pending watchOrderBook or watchTrades promise leaks forever (never resolves, never rejects). Any downstream await hangs until the watch timeout fires, giving the user a timeout error rather than a clear bug report.

Suggested Fix

Ensure the key exists before pushing (mirror the guard used in polymarket/websocket.ts):

if (!this.orderBookResolvers.has(symbol)) this.orderBookResolvers.set(symbol, []);
this.orderBookResolvers.get(symbol)!.push({ resolve, reject });

Or use optional chaining with a fallback:

(this.orderBookResolvers.get(symbol) ?? []).push({ resolve, reject });
// but you'd lose the map entry — the has/set guard is safer

Found by automated non-null assertion 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