Skip to content

NoSuchElementException from ServiceLoader in Async Context #166

@alexstewartja

Description

@alexstewartja

This report details a critical runtime exception encountered for derivatives trading (USDS Futures) within a Play Framework 3 / Pekko environment.

When initializing the WebSocket client within a CompletableFuture (e.g., on Play's default ForkJoinPool), the ServiceLoader mechanism fails to find Jetty WebSocket extension implementations.

  • Error: java.util.NoSuchElementException originating from java.util.ServiceLoader and traced up through org.eclipse.jetty.websocket.api.ExtensionConfig.getParser.
  • Cause: The ServiceLoader relies on the Thread.currentThread().getContextClassLoader(). When the initialization code runs on a worker thread from a thread pool (like ForkJoinPool), this context classloader may not have visibility of the full application dependency classpath where the Jetty service implementations reside.
  • Trigger: Instantiating new DerivativesTradingUsdsFuturesWebSocketStreams(wsConnectionPool) inside a CompletableFuture.supplyAsync() block.

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