@@ -267,11 +267,13 @@ TKeepAliveHttpClient::THttpCode TKeepAliveHttpClient::DoRequestReliable(const T&
267
267
const bool haveNewConnection = CreateNewConnectionIfNeeded ();
268
268
const bool couldRetry = !haveNewConnection && i == 0 ; // Actually old connection could be already closed by server,
269
269
// so we should try one more time in this case.
270
- try {
271
- cancellation.Future ().Subscribe ([&](auto &) {
272
- Connection->Shutdown ();
273
- });
270
+ TManualEvent cancellationEndEvent;
271
+ cancellation.Future ().Subscribe ([&](auto &) {
272
+ Connection->Shutdown ();
273
+ cancellationEndEvent.Signal ();
274
+ });
274
275
276
+ try {
275
277
Connection->Write (raw);
276
278
277
279
THttpCode code = ReadAndTransferHttp (*Connection->GetHttpInput (), output, outHeaders);
@@ -280,20 +282,29 @@ TKeepAliveHttpClient::THttpCode TKeepAliveHttpClient::DoRequestReliable(const T&
280
282
}
281
283
return code;
282
284
} catch (const TSystemError& e) {
285
+ if (cancellation.IsCancellationRequested ()) {
286
+ cancellationEndEvent.WaitI ();
287
+ cancellation.ThrowIfCancellationRequested ();
288
+ }
283
289
Connection.Reset ();
284
- cancellation.ThrowIfCancellationRequested ();
285
290
if (!couldRetry || e.Status () != EPIPE) {
286
291
throw ;
287
292
}
288
293
} catch (const THttpReadException&) { // Actually old connection is already closed by server
294
+ if (cancellation.IsCancellationRequested ()) {
295
+ cancellationEndEvent.WaitI ();
296
+ cancellation.ThrowIfCancellationRequested ();
297
+ }
289
298
Connection.Reset ();
290
- cancellation.ThrowIfCancellationRequested ();
291
299
if (!couldRetry) {
292
300
throw ;
293
301
}
294
302
} catch (const std::exception&) {
303
+ if (cancellation.IsCancellationRequested ()) {
304
+ cancellationEndEvent.WaitI ();
305
+ cancellation.ThrowIfCancellationRequested ();
306
+ }
295
307
Connection.Reset ();
296
- cancellation.ThrowIfCancellationRequested ();
297
308
throw ;
298
309
}
299
310
}
0 commit comments