@@ -457,8 +457,8 @@ func (w *ProcessingWorkflow) SessionHandler(sessCtx temporalsdk_workflow.Context
457457 if tinfo .WatcherName != "" && ! tinfo .IsDir {
458458 // TODO: even if TempFile is defined, we should confirm that the file is
459459 // locally available in disk, just in case we're in the context of a
460- // session retry where a different working is doing the work. In that
461- // case, the activity whould be executed again.
460+ // session retry where a different worker is doing the work. In that
461+ // case, the activity would be executed again.
462462 if tinfo .TempFile == "" {
463463 activityOpts := withActivityOptsForLongLivedRequest (sessCtx )
464464 err := temporalsdk_workflow .ExecuteActivity (
@@ -475,6 +475,9 @@ func (w *ProcessingWorkflow) SessionHandler(sessCtx temporalsdk_workflow.Context
475475 }
476476 }
477477
478+ // Both of these values relate to temporary files on Enduro's processing Dir that never get cleaned-up.
479+ var tempBlob , tempExtracted string
480+ tempBlob = tinfo .TempFile
478481 // Extract downloaded archive file contents.
479482 {
480483 if tinfo .WatcherName != "" && ! tinfo .IsDir {
@@ -497,6 +500,7 @@ func (w *ProcessingWorkflow) SessionHandler(sessCtx temporalsdk_workflow.Context
497500 tinfo .TempFile = result .ExtractPath
498501 tinfo .StripTopLevelDir = false
499502 tinfo .IsDir = true
503+ tempExtracted = result .ExtractPath
500504 }
501505 }
502506 }
@@ -523,11 +527,25 @@ func (w *ProcessingWorkflow) SessionHandler(sessCtx temporalsdk_workflow.Context
523527
524528 // Delete local temporary files.
525529 defer func () {
530+ // We need disconnected context here because when session gets released the cleanup
531+ // activities get scheduled and then immediately canceled.
532+ var filesToRemove []string
526533 if tinfo .Bundle .FullPathBeforeStrip != "" {
527- activityOpts := withActivityOptsForLocalAction (sessCtx )
528- _ = temporalsdk_workflow .ExecuteActivity (activityOpts , activities .CleanUpActivityName , & activities.CleanUpActivityParams {
529- FullPath : tinfo .Bundle .FullPathBeforeStrip ,
530- }).Get (activityOpts , nil )
534+ filesToRemove = append (filesToRemove , tinfo .Bundle .FullPathBeforeStrip )
535+ }
536+ if tempBlob != "" {
537+ filesToRemove = append (filesToRemove , tempBlob )
538+ }
539+ if tempExtracted != "" {
540+ filesToRemove = append (filesToRemove , tempExtracted )
541+ }
542+ cleanUpCtx , cancel := temporalsdk_workflow .NewDisconnectedContext (sessCtx )
543+ defer cancel ()
544+ activityOpts := withActivityOptsForLocalAction (cleanUpCtx )
545+ if err := temporalsdk_workflow .ExecuteActivity (activityOpts , activities .CleanUpActivityName , & activities.CleanUpActivityParams {
546+ Paths : filesToRemove ,
547+ }).Get (activityOpts , nil ); err != nil {
548+ w .logger .Error (err , "failed to clean up temporary files" , "path" , tempExtracted )
531549 }
532550 }()
533551
0 commit comments