google / martian

Martian is a library for building custom HTTP/S proxies
Apache License 2.0
2.01k stars 247 forks source link

id_modifier error #323

Closed lukaskim-lunit closed 3 years ago

lukaskim-lunit commented 3 years ago

I'm trying to use id_modifier to add transaction ID to header, and configured KrakenD like this.

"extra_config": {
  "github.com/devopsfaith/krakend-martian": {
    "header.Id": {
      "scope": ["request"]
    }
  }
}

But KrakenD is giving me error like,

2021/09/01 09:09:37 [Recovery] 2021/09/01 - 09:09:37 panic recovered:
runtime error: invalid memory address or nil pointer dereference
/usr/local/go/src/runtime/panic.go:212 (0xd4e35a)
/usr/local/go/src/runtime/signal_unix.go:734 (0xd67512)
/go/pkg/mod/github.com/google/martian@v2.1.1-0.20190517191504-25dcb96d9e51+incompatible/context.go:185 (0x1790d38)
/go/pkg/mod/github.com/google/martian@v2.1.1-0.20190517191504-25dcb96d9e51+incompatible/header/id_modifier.go:53 (0x1790d2a)
/go/pkg/mod/github.com/devopsfaith/krakend-martian@v1.4.0/martian.go:102 (0x179b2f8)
/go/pkg/mod/github.com/devopsfaith/krakend-martian@v1.4.0/martian.go:63 (0x179c1a4)
/go/pkg/mod/github.com/luraproject/lura@v1.4.1/proxy/http.go:68 (0x10ed22f)
/go/pkg/mod/github.com/luraproject/lura@v1.4.1/proxy/balancing.go:76 (0x10ebfb6)
/go/pkg/mod/github.com/luraproject/lura@v1.4.1/proxy/http.go:109 (0x10ed950)
/go/pkg/mod/github.com/luraproject/lura@v1.4.1/router/gin/endpoint.go:40 (0x191d611)
/go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/context.go:165 (0x1917a79)
/go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/recovery.go:99 (0x1917a60)
/go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/context.go:165 (0x1916b53)
/go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/logger.go:241 (0x1916b12)
/go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/context.go:165 (0x190cd09)
/go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/gin.go:489 (0x190ccef)
/go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/gin.go:445 (0x190c7db)
/go/pkg/mod/github.com/rs/cors@v1.6.0/cors.go:207 (0x1e2d910)
/usr/local/go/src/net/http/server.go:2069 (0x10acc43)
/go/pkg/mod/github.com/rs/cors@v1.6.0/cors.go:207 (0x1e2d910)
/usr/local/go/src/net/http/server.go:2069 (0x10acc43)
/usr/local/go/src/net/http/server.go:2887 (0x10b0302)
/usr/local/go/src/net/http/server.go:1952 (0x10ab72c)
/usr/local/go/src/runtime/asm_amd64.s:1371 (0xd88e40)

Is my configuration wrong? or is it a bug?

bramhaghosh commented 3 years ago

This looks like the context isn't getting linked for the request, which happens in p.handle here: https://github.com/google/martian/blob/7e75073889cd2324f33b959c4fb4545440da046c/proxy.go#L453

So, it seems that ModifyRequest is getting called on the modifier before proxy.Handle. This is common for tests, and we use context.TestContext to get around this. I don't see any other way for that to happen in Martian, so my guess is that this is happening because of how Kraken does something.

I'm not at all familiar with Kraken, but my best guess is that it's because the context is unlinked before this call to modifyRequest (which then calls ModifyRequest() on the id_modifier). https://github.com/devopsfaith/krakend-martian/blob/19be522824c83c2d8541d0a7880cad4f1896248c/martian.go#L63

I don't think this is a Martian bug so I'm going to close this, but feel free to re-open or create a new bug if it turns out I'm wrong.

On Wed, Sep 1, 2021 at 5:11 AM lukaskim-lunit @.***> wrote:

I'm trying to use id_modifier to add transaction ID to header, and configured KrakenD like this.

"extra_config": { "github.com/devopsfaith/krakend-martian": { "header.Id": { "scope": ["request"] } } }

But KrakenD is giving me error like,

2021/09/01 09:09:37 [Recovery] 2021/09/01 - 09:09:37 panic recovered: runtime error: invalid memory address or nil pointer dereference /usr/local/go/src/runtime/panic.go:212 (0xd4e35a) /usr/local/go/src/runtime/signal_unix.go:734 (0xd67512) @.+incompatible/context.go:185 (0x1790d38) @.+incompatible/header/id_modifier.go:53 (0x1790d2a) @./martian.go:102 (0x179b2f8) @./martian.go:63 (0x179c1a4) @./proxy/http.go:68 (0x10ed22f) @./proxy/balancing.go:76 (0x10ebfb6) @./proxy/http.go:109 (0x10ed950) @./router/gin/endpoint.go:40 (0x191d611) @./context.go:165 (0x1917a79) @./recovery.go:99 (0x1917a60) @./context.go:165 (0x1916b53) @./logger.go:241 (0x1916b12) @./context.go:165 (0x190cd09) @./gin.go:489 (0x190ccef) @./gin.go:445 (0x190c7db) @./cors.go:207 (0x1e2d910) /usr/local/go/src/net/http/server.go:2069 (0x10acc43) @.***/cors.go:207 (0x1e2d910) /usr/local/go/src/net/http/server.go:2069 (0x10acc43) /usr/local/go/src/net/http/server.go:2887 (0x10b0302) /usr/local/go/src/net/http/server.go:1952 (0x10ab72c) /usr/local/go/src/runtime/asm_amd64.s:1371 (0xd88e40)

Is my configuration wrong? or is it a bug?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/google/martian/issues/323, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMR6ISTWGM4EEOI2IXQKTT7XU5LANCNFSM5DGADDSA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.