Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 20, 2025

Plan: Add SIGTERM Signal Handling to Flush Logs

  • Understand the current codebase structure (client, plugin, logging)
  • Create signal handler function for SIGTERM that flushes logs
  • Integrate signal handler into plugin (cmd/plugin.go)
  • Integrate signal handler into client commands (cmd/object_copy.go and related files)
  • Add optional SIGQUIT handler when Debug mode is enabled
  • Write tests for signal handling functionality
  • Build and test the changes
  • Run code review and security checks
  • Fix linter errors

Implementation Complete ✅

Changes Made:

  1. Created Signal Handler Infrastructure (client/signal_handler.go, client/signal_handler_windows.go)

    • SetupSignalHandlers() function that listens for SIGTERM
    • Flushes logs using existing logging.FlushLogs()
    • Syncs stdout/stderr file descriptors
    • Optionally sends SIGQUIT in debug mode for stack traces
    • Cross-platform support (Unix/Windows)
  2. Integrated Signal Handlers into All Entry Points

    • Plugin: cmd/plugin.go (stashPluginMain)
    • Client commands: All cmd/object_*.go files
      • object_copy.go, object_get.go, object_put.go
      • object_delete.go, object_ls.go, object_prestage.go
      • object_share.go, object_stat.go, object_sync.go
  3. Comprehensive Testing (client/signal_handler_test.go)

    • All tests pass ✅
  4. Security & Quality

    • CodeQL: 0 vulnerabilities ✅
    • Linter: All issues fixed ✅ (removed trailing whitespace)
    • Go vet: Passed ✅

Linter Fix:

Removed trailing whitespace from client/signal_handler_test.go to fix gofmt warnings.

Original prompt

This section details on the original issue you should resolve

<issue_title>Flush logs / stdout / stderr on SIGTERM</issue_title>
<issue_description>Pelican Service:

  • Client
  • Plugin
  • Registry
  • Director
  • Origin
  • Cache
  • Other (please give the detail)

Is your feature request related to a problem? Please describe.
We are trying to track down a Pelican issue in the CHTC where 1% or so of execution attempts appear stuck for 1h before being killed by HTCondor. Unfortunately, HTCondor sends a SIGTERM and it appears that we lose any useful information because Pelican is only flushing logs / stdout / stderr upon successful completion.

Describe the solution you'd like
The Pelican client / plugin should flush all messages to logs, stdout, and stderr upon receiving a SIGTERM and then exit.

Optionally, it sounds like Go binaries have a SIGQUIT handler that dumps stack, so we may want the client / plugin to send a SIGQUIT to itself if say Debug: true

Additional context
Add any other context or screenshots about the feature request here.
</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Flush logs and output on SIGTERM signal Flush logs/stdout/stderr on SIGTERM in client and plugin Nov 20, 2025
Copilot AI requested a review from patrickbrophy November 20, 2025 16:36
@patrickbrophy
Copy link
Contributor

@copilot It looks like the linter failed, can take a look?

Copy link
Contributor Author

Copilot AI commented Nov 20, 2025

@copilot It looks like the linter failed, can take a look?

Fixed in fecb630. Removed trailing whitespace from signal_handler_test.go that was causing gofmt warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flush logs / stdout / stderr on SIGTERM

2 participants