-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix pre-receive hook hangs and missing logs by flushing logs on signal and using CommandContext for git commands #4714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jordanTunstill
wants to merge
10
commits into
main
Choose a base branch
from
AddLogFlushing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+62
−14
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f12e1c9
Fix pre-receive hook hangs and missing logs by flushing logs on signa…
jordanTunstill 296302c
Make git command WaitDelay configurable
jordanTunstill 3af2ec5
Merge branch 'main' into AddLogFlushing
jordanTunstill f8221bd
added a test for wait delay
jordanTunstill 08e18b4
Merge branch 'main' into AddLogFlushing
jordanTunstill 7ee8c30
Refactor log sync to use function parameter instead of package variable
jordanTunstill 1bf71bd
removed timeout from function, retained log flushing when scan is kil…
jordanTunstill 1fabc84
removed unused time import, since i no longer need to add it.
jordanTunstill c5a2796
moved flush out of a goroutine as the timeout has been removed.
jordanTunstill 36e8178
remove function wrapper for syncLogs
jordanTunstill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,6 @@ import ( | |
| "strings" | ||
| "sync" | ||
| "syscall" | ||
|
|
||
| "github.com/alecthomas/kingpin/v2" | ||
| "github.com/fatih/color" | ||
| "github.com/felixge/fgprof" | ||
|
|
@@ -347,6 +346,19 @@ func init() { | |
| } | ||
| } | ||
|
|
||
| // syncLogs flushes logs when the program exits. | ||
| func syncLogs(syncFn func() error) { | ||
| if syncFn == nil { | ||
| return | ||
| } | ||
| done := make(chan struct{}) | ||
| go func() { | ||
| _ = syncFn() | ||
| close(done) | ||
| }() | ||
| <-done | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| func main() { | ||
| // setup logger | ||
| logFormat := log.WithConsoleSink | ||
|
|
@@ -358,15 +370,16 @@ func main() { | |
| context.SetDefaultLogger(logger) | ||
|
|
||
| if *localDev { | ||
| run(overseer.State{}) | ||
| run(overseer.State{}, sync) | ||
| os.Exit(0) | ||
| } | ||
|
|
||
| defer func() { _ = sync() }() | ||
| logFatal := logFatalFunc(logger) | ||
|
|
||
| updateCfg := overseer.Config{ | ||
| Program: run, | ||
| Program: func(s overseer.State) { | ||
| run(s, sync) | ||
| }, | ||
| Debug: *debug, | ||
| RestartSignal: syscall.SIGTERM, | ||
| // TODO: Eventually add a PreUpgrade func for signature check w/ x509 PKCS1v15 | ||
|
|
@@ -387,10 +400,12 @@ func main() { | |
| } | ||
| } | ||
|
|
||
| func run(state overseer.State) { | ||
|
|
||
| func run(state overseer.State, logSync func() error) { | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ctx, cancel := context.WithCancelCause(context.Background()) | ||
| defer cancel(nil) | ||
| defer func() { | ||
| syncLogs(logSync) | ||
| }() | ||
|
||
|
|
||
| go func() { | ||
| if err := cleantemp.CleanTempArtifacts(ctx); err != nil { | ||
|
|
@@ -413,6 +428,8 @@ func run(state overseer.State) { | |
| } else { | ||
| logger.Info("cleaned temporary artifacts") | ||
| } | ||
|
|
||
| syncLogs(logSync) | ||
| os.Exit(0) | ||
| }() | ||
|
|
||
|
|
@@ -606,6 +623,7 @@ func run(state overseer.State) { | |
|
|
||
| if metrics.hasFoundResults && *fail { | ||
| logger.V(2).Info("exiting with code 183 because results were found") | ||
| syncLogs(logSync) | ||
| os.Exit(183) | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


Uh oh!
There was an error while loading. Please reload this page.