@@ -77,6 +77,7 @@ type DatadogSymbolUploader struct {
7777 retrievalQueue chan * reporter.ExecutableMetadata
7878 pipeline pipeline.Pipeline [* reporter.ExecutableMetadata ]
7979 mut sync.Mutex
80+ biggestBinarySize int64
8081}
8182
8283type goPCLnTabDump struct {
@@ -449,6 +450,18 @@ func newSymbolUploadRequestMetadata(e *symbol.Elf, symbolSource symbol.Source, p
449450 }
450451}
451452
453+ func (d * DatadogSymbolUploader ) updateBiggestBinarySize (size int64 ) {
454+ for {
455+ current := atomic .LoadInt64 (& d .biggestBinarySize )
456+ if current >= size {
457+ break
458+ }
459+ if atomic .CompareAndSwapInt64 (& d .biggestBinarySize , current , size ) {
460+ break
461+ }
462+ }
463+ }
464+
452465func (d * DatadogSymbolUploader ) createSymbolFile (ctx context.Context , e * symbol.Elf ) (* os.File , error ) {
453466 symbolFile , err := os .CreateTemp ("" , "objcopy-debug" )
454467 if err != nil {
@@ -481,7 +494,14 @@ func (d *DatadogSymbolUploader) createSymbolFile(ctx context.Context, e *symbol.
481494 sectionsToKeep = e .GetSectionsRequiredForDynamicSymbols ()
482495 }
483496
497+ d .updateBiggestBinarySize (e .GetSize ())
484498 err = CopySymbols (ctx , elfPath , symbolFile .Name (), goPCLnTabInfo , sectionsToKeep , d .compressDebugSections )
499+
500+ var exitError * exec.ExitError
501+ if errors .As (err , & exitError ) && exitError .ExitCode () == - 1 { // killed by signal
502+ return nil , fmt .Errorf ("failed to copy symbols: got killed. Consider increasing memory limits to at least %v (biggest uncompressed elf file size found)" , atomic .LoadInt64 (& d .biggestBinarySize ))
503+ }
504+
485505 if err != nil {
486506 return nil , fmt .Errorf ("failed to copy symbols: %w" , err )
487507 }
@@ -590,7 +610,7 @@ func CopySymbols(ctx context.Context, inputPath, outputPath string, goPCLnTabInf
590610 if err := cmd .Wait (); err != nil {
591611 var ExitError * exec.ExitError
592612 if errors .As (err , & ExitError ) && ExitError .ExitCode () == - 1 { // killed by signal
593- return fmt . Errorf ( "got killed. Consider increasing memory limits to at least %v (biggest uncompressed elf file size found)" , atomic . LoadInt64 ( & symbol . BiggestBinarySize ))
613+ return ExitError
594614 }
595615 return fmt .Errorf ("failed to extract debug symbols: %w" , cleanCmdError (err ))
596616 }
0 commit comments