Browse Source

Fix missing early return in error's update tracing attributes method and UB in host name parcing
commit_hash:cc382538d686689db47047d08624b01ac8893464

arkady-e1ppa 5 months ago
parent
commit
8a06db32ea
2 changed files with 19 additions and 2 deletions
  1. 4 1
      yt/yt/core/misc/error.cpp
  2. 15 1
      yt/yt/core/misc/stripped_error.cpp

+ 4 - 1
yt/yt/core/misc/error.cpp

@@ -69,7 +69,9 @@ void TryExtractHost(const TOriginAttributes& attributes)
         spanId
     ] = Decode(*attributes.ExtensionData);
 
-    attributes.Host = name;
+    attributes.Host = name
+        ? TStringBuf(name)
+        : TStringBuf{};
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -125,6 +127,7 @@ void UpdateTracingAttributes(TOriginAttributes* attributes, const NTracing::TTra
             .TraceId = tracingAttributes.TraceId,
             .SpanId = tracingAttributes.SpanId,
         }));
+        return;
     }
 
     attributes->ExtensionData.emplace(Encode(TExtensionData{

+ 15 - 1
yt/yt/core/misc/stripped_error.cpp

@@ -797,7 +797,21 @@ void AppendError(TStringBuilderBase* builder, const TError& error, int indent)
 
     for (const auto& [key, value] : error.Attributes().ListPairs()) {
         TTokenizer tokenizer(value.AsStringBuf());
-        YT_VERIFY(tokenizer.ParseNext());
+        // TODO(arkady-e1ppa): Remove this once failed verifies have been dealt with.
+        [[unlikely]] if (!tokenizer.ParseNext()) {
+            Cerr <<
+                NYT::Format(
+                    "%v *** Empty toke encountered while formatting TError attribute (Key: %v, Value: %v"
+                    "(BuilderAccumulatedData: %v)",
+                    TInstant::Now(),
+                    key,
+                    value.AsStringBuf(),
+                    builder->GetBuffer())
+                << '\n';
+            Flush(Cerr);
+            YT_ABORT();
+        }
+        // YT_VERIFY(tokenizer.ParseNext());
         switch (tokenizer.GetCurrentType()) {
             case ETokenType::String:
                 AppendAttribute(builder, key, TString(tokenizer.CurrentToken().GetStringValue()), indent);