Describe the bug
OkHttpFutureCallback.onResponse() does not complete its CompletableFuture when response processing fails with an exception other than TelegramApiRequestException.
In particular, ResponseBody.string() may throw an IOException, for example SocketException: Socket closed. The exception escapes from onResponse(), but the future is neither completed normally nor exceptionally.
Synchronous calls waiting in AbstractTelegramClient.execute() may therefore block indefinitely on CompletableFuture.get().
To reproduce
- Create an
OkHttpFutureCallback.
- Pass it a successful HTTP response whose
ResponseBody throws SocketException while being read.
- Invoke
onResponse().
- Observe that the exception escapes and the future remains incomplete.
A regression test reproducing this behavior is included in the proposed fix.
Expected behavior
Every response-processing failure should complete the future exceptionally. No execution path from onResponse() should leave the future incomplete.
Environment
- TelegramBots: 10.1.1
- Java: 17
- Affected component:
telegrambots-client
Additional context
OkHttp has already delivered the call to onResponse(), so onFailure() is not subsequently invoked for an exception thrown while processing that response.
The proposed fix catches response-processing exceptions, completes the future exceptionally, and adds a regression test using SocketException: Socket closed.
Describe the bug
OkHttpFutureCallback.onResponse()does not complete itsCompletableFuturewhen response processing fails with an exception other thanTelegramApiRequestException.In particular,
ResponseBody.string()may throw anIOException, for exampleSocketException: Socket closed. The exception escapes fromonResponse(), but the future is neither completed normally nor exceptionally.Synchronous calls waiting in
AbstractTelegramClient.execute()may therefore block indefinitely onCompletableFuture.get().To reproduce
OkHttpFutureCallback.ResponseBodythrowsSocketExceptionwhile being read.onResponse().A regression test reproducing this behavior is included in the proposed fix.
Expected behavior
Every response-processing failure should complete the future exceptionally. No execution path from
onResponse()should leave the future incomplete.Environment
telegrambots-clientAdditional context
OkHttp has already delivered the call to
onResponse(), soonFailure()is not subsequently invoked for an exception thrown while processing that response.The proposed fix catches response-processing exceptions, completes the future exceptionally, and adds a regression test using
SocketException: Socket closed.