Skip to content

Commit 7639659

Browse files
committed
Refine comments
Signed-off-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
1 parent 3a8745b commit 7639659

3 files changed

Lines changed: 14 additions & 31 deletions

File tree

‎mcp-core/src/main/java/io/modelcontextprotocol/client/transport/ResponseBodyHandlers.java‎

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -197,25 +197,14 @@ static <T> Flux<T> cancel(Publisher<List<ByteBuffer>> body) {
197197
});
198198
}
199199

200-
/**
201-
* Sends {@code request}, handing the response body over as a publisher.
202-
*
203-
* <p>
204-
* Such a body must be subscribed to, or the connection it is read from is never
205-
* released. Should the exchange be cancelled once the response has arrived but before
206-
* its body could be subscribed to, the response is discarded, and its body cancelled.
207-
*
208-
* <p>
209-
* Cancelling the exchange before the response has arrived aborts the request. The
210-
* {@link HttpClient} then fails its future with a {@link CompletionException}
211-
* wrapping a {@link CancellationException}, which {@link Mono#fromFuture} does not
212-
* recognise as the outcome of its own cancellation and reports as a dropped error.
213-
* Only this method can cancel the future, so such a failure is always the expected
214-
* outcome of cancelling, and is ignored.
215-
* @param httpClient the client to send the request with
216-
* @param request the request to send
217-
*/
218200
static Mono<HttpResponse<Publisher<List<ByteBuffer>>>> sendAsync(HttpClient httpClient, HttpRequest request) {
201+
// Not Mono.fromFuture: cancelling aborts the exchange, and the HttpClient then
202+
// fails the future with a CompletionException wrapping a CancellationException,
203+
// which fromFuture reports as a dropped error. Only this method cna cancel the
204+
// future, so that failure is ignored here. Replace with a plain fromFuture,
205+
// keeping
206+
// the doOnDiscard, once https://github.com/reactor/reactor-core/issues/4415 is
207+
// resolved.
219208
return Mono.<HttpResponse<Publisher<List<ByteBuffer>>>>create(sink -> {
220209
CompletableFuture<HttpResponse<Publisher<List<ByteBuffer>>>> exchange = httpClient.sendAsync(request,
221210
HttpResponse.BodyHandlers.ofPublisher());
@@ -238,11 +227,13 @@ static Mono<HttpResponse<Publisher<List<ByteBuffer>>>> sendAsync(HttpClient http
238227
sink.error(cause);
239228
}
240229
});
241-
}).doOnDiscard(HttpResponse.class, response -> {
242-
if (response.body() instanceof Publisher<?> body) {
243-
cancelBody(body);
244-
}
245-
});
230+
})
231+
// A body that is never subscribed to never releases its connection.
232+
.doOnDiscard(HttpResponse.class, response -> {
233+
if (response.body() instanceof Publisher<?> body) {
234+
cancelBody(body);
235+
}
236+
});
246237
}
247238

248239
private static void cancelBody(Publisher<?> body) {

‎mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientSseClientTransportConnectTests.java‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323

2424
import static org.assertj.core.api.Assertions.assertThat;
2525

26-
/**
27-
* Verifies that {@link HttpClientSseClientTransport#connect} always resolves, even when
28-
* the SSE stream ends, fails or is closed before its first event.
29-
*/
3026
class HttpClientSseClientTransportConnectTests {
3127

3228
// Only bounds a regression: every test resolves without waiting on it.

‎mcp-core/src/test/java/io/modelcontextprotocol/client/transport/HttpClientStreamableHttpTransportSendMessageTests.java‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626

2727
import static org.assertj.core.api.Assertions.assertThat;
2828

29-
/**
30-
* Verifies that {@link HttpClientStreamableHttpTransport#sendMessage} always resolves,
31-
* and that it fails when the server's response to it cannot be read.
32-
*/
3329
class HttpClientStreamableHttpTransportSendMessageTests {
3430

3531
// Only bounds a regression: every test resolves without waiting on it.

0 commit comments

Comments
 (0)