Skip to content

Commit c3d7951

Browse files
and42blinkov
authored andcommitted
return/make useful coordinator_new TestFetchGraphCancel
commit_hash:4721e3d84bd7a730a2fc5be4d0e42da14ef16c40
1 parent 36e50d3 commit c3d7951

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

library/cpp/http/simple/http_client.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,13 @@ TKeepAliveHttpClient::THttpCode TKeepAliveHttpClient::DoRequestReliable(const T&
267267
const bool haveNewConnection = CreateNewConnectionIfNeeded();
268268
const bool couldRetry = !haveNewConnection && i == 0; // Actually old connection could be already closed by server,
269269
// 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+
});
274275

276+
try {
275277
Connection->Write(raw);
276278

277279
THttpCode code = ReadAndTransferHttp(*Connection->GetHttpInput(), output, outHeaders);
@@ -280,20 +282,29 @@ TKeepAliveHttpClient::THttpCode TKeepAliveHttpClient::DoRequestReliable(const T&
280282
}
281283
return code;
282284
} catch (const TSystemError& e) {
285+
if (cancellation.IsCancellationRequested()) {
286+
cancellationEndEvent.WaitI();
287+
cancellation.ThrowIfCancellationRequested();
288+
}
283289
Connection.Reset();
284-
cancellation.ThrowIfCancellationRequested();
285290
if (!couldRetry || e.Status() != EPIPE) {
286291
throw;
287292
}
288293
} catch (const THttpReadException&) { // Actually old connection is already closed by server
294+
if (cancellation.IsCancellationRequested()) {
295+
cancellationEndEvent.WaitI();
296+
cancellation.ThrowIfCancellationRequested();
297+
}
289298
Connection.Reset();
290-
cancellation.ThrowIfCancellationRequested();
291299
if (!couldRetry) {
292300
throw;
293301
}
294302
} catch (const std::exception&) {
303+
if (cancellation.IsCancellationRequested()) {
304+
cancellationEndEvent.WaitI();
305+
cancellation.ThrowIfCancellationRequested();
306+
}
295307
Connection.Reset();
296-
cancellation.ThrowIfCancellationRequested();
297308
throw;
298309
}
299310
}

0 commit comments

Comments
 (0)