Skip to content
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

Running blogrenderer benchmark test causes panic #638

Open
logan-connolly opened this issue Feb 8, 2023 · 1 comment
Open

Running blogrenderer benchmark test causes panic #638

logan-connolly opened this issue Feb 8, 2023 · 1 comment

Comments

@logan-connolly
Copy link

Hey @quii,

First off, thanks so much for this amazing learning resource. It has helped me so much!

As the title suggest, running BenchmarkRender causes a panic. It seems that the blogrender unit tests run fine because postRenderer.Render is only called only once, but as soon as you call it again, you can reproduce the panic.

Traceback
learn-go-with-tests/blogrenderer  main 🐹 v1.20
❯ go test -bench=.
goos: linux
goarch: amd64
pkg: github.com/quii/learn-go-with-tests/blogrenderer
cpu: Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz
BenchmarkRender-12      panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x5c53d1]

goroutine 35 [running]:
github.com/gomarkdown/markdown/parser.(*Parser).finalize(...)
        /home/archie/go/pkg/mod/github.com/gomarkdown/[email protected]/parser/parser.go:206
github.com/gomarkdown/markdown/parser.(*Parser).addChild(0xc0000a6000, {0x6dc6b0?, 0xc000028900})
        /home/archie/go/pkg/mod/github.com/gomarkdown/[email protected]/parser/parser.go:211 +0x71
github.com/gomarkdown/markdown/parser.(*Parser).addBlock(0xc0000a6000, {0x6dc6b0, 0xc000028900})
        /home/archie/go/pkg/mod/github.com/gomarkdown/[email protected]/parser/block.go:392 +0x105
github.com/gomarkdown/markdown/parser.(*Parser).renderParagraph(0xc000018320?, {0xc000018320, 0x10?, 0x10})
        /home/archie/go/pkg/mod/github.com/gomarkdown/[email protected]/parser/block.go:1548 +0x10a
github.com/gomarkdown/markdown/parser.(*Parser).paragraph(0xc0000a6000, {0xc000018320, 0xe, 0x10})
        /home/archie/go/pkg/mod/github.com/gomarkdown/[email protected]/parser/block.go:1711 +0x53f
github.com/gomarkdown/markdown/parser.(*Parser).block(0xc0000a6000, {0xc000018320?, 0xc000211ad8?, 0x5e57a4?})
        /home/archie/go/pkg/mod/github.com/gomarkdown/[email protected]/parser/block.go:373 +0xf1c
github.com/gomarkdown/markdown/parser.(*Parser).Parse(0xc0000a6000, {0xc000018320?, 0x65d000?, 0xc0000288a0?})
        /home/archie/go/pkg/mod/github.com/gomarkdown/[email protected]/parser/parser.go:272 +0x3e
github.com/gomarkdown/markdown.Parse({0xc000018320?, 0x0?, 0x99?}, 0x65d000?)
        /home/archie/go/pkg/mod/github.com/gomarkdown/[email protected]/markdown.go:53 +0x65
github.com/gomarkdown/markdown.ToHTML({0xc000018320?, 0x68a75c?, 0xe?}, 0x6893de?, {0x0, 0x0})
        /home/archie/go/pkg/mod/github.com/gomarkdown/[email protected]/markdown.go:77 +0x45
github.com/quii/learn-go-with-tests/blogrenderer.newPostVM(...)
        /home/archie/projects/work/learn-go-with-tests-source/blogrenderer/renderer.go:52
github.com/quii/learn-go-with-tests/blogrenderer.(*PostRenderer).Render(0xc000060300, {0x6da980, 0x88df00}, {{0x689512, 0xb}, {0x68d96e, 0x15}, {0x68a75c, 0xe}, {0xc00006c000, ...}})
        /home/archie/projects/work/learn-go-with-tests-source/blogrenderer/renderer.go:37 +0x125
github.com/quii/learn-go-with-tests/blogrenderer_test.BenchmarkRender(0xc00010a280)
        /home/archie/projects/work/learn-go-with-tests-source/blogrenderer/renderer_test.go:68 +0x1b3
testing.(*B).runN(0xc00010a280, 0x64)
        /usr/lib/go/src/testing/benchmark.go:193 +0x102
testing.(*B).launch(0xc00010a280)
        /usr/lib/go/src/testing/benchmark.go:334 +0x1c5
created by testing.(*B).doBench
        /usr/lib/go/src/testing/benchmark.go:284 +0x6c
exit status 2
FAIL    github.com/quii/learn-go-with-tests/blogrenderer        0.007s

Hope this helps and thanks again for all your hard work!

@cativovo
Copy link

Hi, I also encountered the issue. I think the cause of the panic is the reuse of the Parser. Here's a related issue from gomarkdown - gomarkdown/markdown#280. Hope this helps. Thank you for all the hard work.

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

No branches or pull requests

2 participants