@@ -746,7 +746,7 @@ friend class IHTTPGateway;
746
746
}
747
747
748
748
size_t FillHandlers () {
749
- const std::unique_lock lock (Sync );
749
+ const std::unique_lock lock (SyncRef () );
750
750
for (auto it = Streams.cbegin (); Streams.cend () != it;) {
751
751
if (const auto & stream = it->lock ()) {
752
752
const auto streamHandle = stream->GetHandle ();
@@ -795,7 +795,7 @@ friend class IHTTPGateway;
795
795
TEasyCurl::TPtr easy;
796
796
long httpResponseCode = 0L ;
797
797
{
798
- const std::unique_lock lock (Sync );
798
+ const std::unique_lock lock (SyncRef () );
799
799
if (const auto it = Allocated.find (handle); Allocated.cend () != it) {
800
800
easy = std::move (it->second );
801
801
TString codeLabel;
@@ -847,7 +847,7 @@ friend class IHTTPGateway;
847
847
void Fail (CURLMcode result) {
848
848
std::stack<TEasyCurl::TPtr> works;
849
849
{
850
- const std::unique_lock lock (Sync );
850
+ const std::unique_lock lock (SyncRef () );
851
851
852
852
for (auto & item : Allocated) {
853
853
works.emplace (std::move (item.second ));
@@ -868,7 +868,7 @@ friend class IHTTPGateway;
868
868
void Upload (TString url, THeaders headers, TString body, TOnResult callback, bool put, TRetryPolicy::TPtr retryPolicy) final {
869
869
Rps->Inc ();
870
870
871
- const std::unique_lock lock (Sync );
871
+ const std::unique_lock lock (SyncRef () );
872
872
auto easy = TEasyCurlBuffer::Make (InFlight, DownloadedBytes, UploadedBytes, std::move (url), put ? TEasyCurl::EMethod::PUT : TEasyCurl::EMethod::POST, std::move (body), std::move (headers), 0U , 0U , std::move (callback), retryPolicy ? retryPolicy->CreateRetryState () : nullptr , InitConfig, DnsGateway.GetDNSCurlList ());
873
873
Await.emplace (std::move (easy));
874
874
Wakeup (0U );
@@ -877,7 +877,7 @@ friend class IHTTPGateway;
877
877
void Delete (TString url, THeaders headers, TOnResult callback, TRetryPolicy::TPtr retryPolicy) final {
878
878
Rps->Inc ();
879
879
880
- const std::unique_lock lock (Sync );
880
+ const std::unique_lock lock (SyncRef () );
881
881
auto easy = TEasyCurlBuffer::Make (InFlight, DownloadedBytes, UploadedBytes, std::move (url), TEasyCurl::EMethod::DELETE, 0 , std::move (headers), 0U , 0U , std::move (callback), retryPolicy ? retryPolicy->CreateRetryState () : nullptr , InitConfig, DnsGateway.GetDNSCurlList ());
882
882
Await.emplace (std::move (easy));
883
883
Wakeup (0U );
@@ -898,7 +898,7 @@ friend class IHTTPGateway;
898
898
callback (TResult (CURLE_OK, TIssues{error}));
899
899
return ;
900
900
}
901
- const std::unique_lock lock (Sync );
901
+ const std::unique_lock lock (SyncRef () );
902
902
auto easy = TEasyCurlBuffer::Make (InFlight, DownloadedBytes, UploadedBytes, std::move (url), TEasyCurl::EMethod::GET, std::move (data), std::move (headers), offset, sizeLimit, std::move (callback), retryPolicy ? retryPolicy->CreateRetryState () : nullptr , InitConfig, DnsGateway.GetDNSCurlList ());
903
903
Await.emplace (std::move (easy));
904
904
Wakeup (sizeLimit);
@@ -915,13 +915,14 @@ friend class IHTTPGateway;
915
915
const ::NMonitoring::TDynamicCounters::TCounterPtr& inflightCounter) final
916
916
{
917
917
auto stream = TEasyCurlStream::Make (InFlightStreams, DownloadedBytes, UploadedBytes, std::move (url), std::move (headers), offset, sizeLimit, std::move (onStart), std::move (onNewData), std::move (onFinish), inflightCounter, InitConfig, DnsGateway.GetDNSCurlList ());
918
- const std::unique_lock lock (Sync );
918
+ const std::unique_lock lock (SyncRef () );
919
919
const auto handle = stream->GetHandle ();
920
920
TEasyCurlStream::TWeakPtr weak = stream;
921
921
Streams.emplace_back (stream);
922
922
Allocated.emplace (handle, std::move (stream));
923
923
Wakeup (0ULL );
924
- return [weak](TIssue issue) {
924
+ return [weak, sync=Sync](TIssue issue) {
925
+ const std::unique_lock lock (*sync);
925
926
if (const auto & stream = weak.lock ())
926
927
stream->Cancel (issue);
927
928
};
@@ -932,7 +933,7 @@ friend class IHTTPGateway;
932
933
}
933
934
934
935
void OnRetry (TEasyCurlBuffer::TPtr easy) {
935
- const std::unique_lock lock (Sync );
936
+ const std::unique_lock lock (SyncRef () );
936
937
const size_t sizeLimit = easy->GetSizeLimit ();
937
938
Await.emplace (std::move (easy));
938
939
Wakeup (sizeLimit);
@@ -950,6 +951,10 @@ friend class IHTTPGateway;
950
951
}
951
952
952
953
private:
954
+ std::mutex& SyncRef () {
955
+ return *Sync;
956
+ }
957
+
953
958
CURLM* Handle = nullptr ;
954
959
955
960
std::queue<TEasyCurlBuffer::TPtr> Await;
@@ -959,7 +964,7 @@ friend class IHTTPGateway;
959
964
std::unordered_map<CURL*, TEasyCurl::TPtr> Allocated;
960
965
std::priority_queue<std::pair<TInstant, TEasyCurlBuffer::TPtr>> Delayed;
961
966
962
- std::mutex Sync;
967
+ std::shared_ptr<std:: mutex> Sync = std::make_shared<std::mutex>() ;
963
968
std::thread Thread;
964
969
std::atomic<bool > IsStopped = false ;
965
970
0 commit comments