Skip to content

🐛 [Bug]: middleware/recover missing extra \n cause log parser to mismatch stacktrace #3815

@Vovan-VE

Description

@Vovan-VE

Bug Description

_, _ = os.Stderr.WriteString(fmt.Sprintf("panic: %v\n%s\n", e, debug.Stack())) //nolint:errcheck // This will never fail

Current output:

panic: ...
goroutine ...
...
        ...

Real go panic output:

panic: ...

goroutine ...
...
        ...

The missing empty line after panic: line cause a log parser to fail match stacktrace.
https://github.com/fluent/fluent-bit/blob/912b7d783a328c09c82aeb16bd26330a468f2005/src/multiline/flb_ml_parser_go.c#L59-L84

    ret = rule(mlp,
               "start_state",
               "/\\bpanic: /",
               "go_after_panic", NULL);
    // ...
    ret = rule(mlp,
               "go_after_panic",
               "/^$/",
               "go_goroutine", NULL);
    // ...
    ret = rule(mlp,
               "go_goroutine",
               "/^goroutine \\d+ \\[[^\\]]+\\]:$/",
               "go_frame_1", NULL);

How to Reproduce

Steps to reproduce the behavior:

  1. app.Use(recovr.New(recovr.Config{ EnableStackTrace: true }))
  2. panic happened
  3. stderr parsed by a log parser and can successfully parse regular go panic output
  4. but middleware/recover output match only first line without stack trace

Expected Behavior

Adding missing \n will make output the same as regular go panic output, so log parser WILL gather stacktrace too.

-"panic: %v\n%s\n"
+"panic: %v\n\n%s\n"

Fiber Version

v2.52.2

Code Snippet (optional)

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions