Skip to content

MCP: cancelling the disconnect signal logs an UnsupportedOperationException on every request #1764

Done

Description

@jlouvel

Follow-up to #1700. Found while moving an MCP server onto org.restlet.ext.mcp (naftiko/ikanos#838).

Every request the MCP adapter serves logs an ERROR from Reactor, Operator called default onErrorDropped, with an UnsupportedOperationException:

java.lang.UnsupportedOperationException: null
	at java.base/java.util.concurrent.CompletableFuture$MinimalStage.cancel(CompletableFuture.java:2989)
	at reactor.core.publisher.MonoCompletionStage$MonoCompletionStageSubscription.cancel(MonoCompletionStage.java:156)
	at reactor.core.publisher.FluxFirstWithSignal$RaceCoordinator.tryWin(FluxFirstWithSignal.java:275)
	...
	at org.restlet.ext.mcp.internal.McpWorkers.work(McpWorkers.java:145)

Nothing fails, and the response is right, but the log is wrong. It shows 40 times in the HTTP tests of one module, and on the stdio transport it puts a stack trace on stderr for most requests, which is what many clients show to their users.

Cause: Request.getDisconnectSignal() returns disconnectSignal.minimalCompletionStage(), a CompletableFuture subclass whose cancel throws. McpServerAdapter.admit and McpModernExchange turn it into a Mono with Mono.fromCompletionStage(...) and race it against the exchange with Mono.firstWithSignal. When the exchange wins, the race cancels the loser, and MonoCompletionStage calls cancel on the minimal stage.

Delivery:

  1. Subscribe to the disconnect signal without cancelling it: build the Mono from stage.toCompletableFuture() (a copy, which can be cancelled), through one small helper that both call sites use.
  2. A test that serves a request and asserts nothing reaches Reactor's onErrorDropped hook (Hooks.onErrorDropped), over the modern HTTP path and the stdio one.
  3. A line under "Bugs fixed" in changes.md.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions