Skip to content

WebSocketClient.setClient can't borrow a client created without a Context #1599

Open

Description

@jlouvel

Problem

With #1568, WebSocketClient.setClient(Client) lets a WebSocket client share a borrowed client's event loop. It finds the client's NettyClientHelper through the org.restlet.engine.helper context attribute, so it only accepts a client that has a Context.

The most common way to create a client is new Client(Protocol.HTTP), and that client has no context, so it can't be borrowed. start() throws:

The borrowed client must have a context and use the Netty HTTP connector

The workaround is new Client(new Context(), Protocol.HTTP). It's shown in the #1568 description, but it's easy to miss, and the error doesn't say what to change.

Why it matters

setClient is meant to accept the client an application already has. The GraphQL WebSocket client (#1594) borrows the application's client the same way and inherits this restriction.

Proposed direction

  1. Find the helper without going through the context, for example with an engine-level accessor on Client. That way any started client that uses the Netty connector can be borrowed.
  2. Otherwise, keep the context lookup, document the requirement on setClient, and name the fix in the error message.

Option 1 is preferred.

Related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions