Skip to content

log, parallel: fix help flag panicking - #509

Merged
ilkinulas merged 4 commits into
peak:masterfrom
boraberke:fix-help-flag-panic
Sep 13, 2022
Merged

ilkinulas merged 4 commits into
peak:masterfrom
boraberke:fix-help-flag-panic

Conversation

@boraberke

@boraberke boraberke commented Sep 9, 2022

Copy link
Copy Markdown
Contributor

after #495, s5cmd --help started to panic:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x158798e]

goroutine 1 [running]:
github.com/peak/s5cmd/parallel.(*Manager).Close(...)
        /Users/boraberke/Documents/s5cmd/parallel/parallel.go:65
github.com/peak/s5cmd/parallel.Close(...)
        /Users/boraberke/Documents/s5cmd/parallel/global.go:16
github.com/peak/s5cmd/command.glob..func5(0x16af2c0?)
        /Users/boraberke/Documents/s5cmd/command/app.go:177 +0x10e
github.com/urfave/cli/v2.(*App).RunContext.func1()
        /Users/boraberke/Documents/s5cmd/vendor/github.com/urfave/cli/v2/app.go:309 +0x35
github.com/urfave/cli/v2.(*App).RunContext(0x1bf3c20, {0x1857a30?, 0xc000030e80}, {0xc000020040, 0x2, 0x2})
        /Users/boraberke/Documents/s5cmd/vendor/github.com/urfave/cli/v2/app.go:321 +0xa5b
github.com/peak/s5cmd/command.Main({0x1857a30, 0xc000030e80}, {0xc000020040, 0x2, 0x2})
        /Users/boraberke/Documents/s5cmd/command/app.go:235 +0xa6
main.main()
        /Users/boraberke/Documents/s5cmd/main.go:23 +0x9b

This is caused by this commit from urfave/cli. app.After is deferred before showAppHelp is called. Fix this bug by making nil checks in log.go and parallel.go

after peak#495, `s5cmd --help` started to panic:

```
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x158798e]

goroutine 1 [running]:
github.com/peak/s5cmd/parallel.(*Manager).Close(...)
        /Users/boraberkesahin/Documents/s5cmd/parallel/parallel.go:65
github.com/peak/s5cmd/parallel.Close(...)
        /Users/boraberkesahin/Documents/s5cmd/parallel/global.go:16
github.com/peak/s5cmd/command.glob..func5(0x16af2c0?)
        /Users/boraberkesahin/Documents/s5cmd/command/app.go:177 +0x10e
github.com/urfave/cli/v2.(*App).RunContext.func1()
        /Users/boraberkesahin/Documents/s5cmd/vendor/github.com/urfave/cli/v2/app.go:309 +0x35
github.com/urfave/cli/v2.(*App).RunContext(0x1bf3c20, {0x1857a30?, 0xc000030e80}, {0xc000020040, 0x2, 0x2})
        /Users/boraberkesahin/Documents/s5cmd/vendor/github.com/urfave/cli/v2/app.go:321 +0xa5b
github.com/peak/s5cmd/command.Main({0x1857a30, 0xc000030e80}, {0xc000020040, 0x2, 0x2})
        /Users/boraberkesahin/Documents/s5cmd/command/app.go:235 +0xa6
main.main()
        /Users/boraberkesahin/Documents/s5cmd/main.go:23 +0x9b
```

This is caused by (this PR)[urfave/cli@a1c26d5] from urfave/cli. `app.After` is called before `app.Before` is called. Fix this bug by making nil checks.
@boraberke
boraberke requested review from a team, aykutfarsak and ilkinulas and removed request for a team September 9, 2022 11:07

@igungor igungor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test.

aykutfarsak
aykutfarsak previously approved these changes Sep 12, 2022
Comment thread e2e/app_test.go Outdated
@ilkinulas
ilkinulas merged commit 88a4641 into peak:master Sep 13, 2022
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.

4 participants