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

Error: invalid memory address or nil pointer dereference #18629

Closed
pboguslawski opened this issue Feb 5, 2022 · 6 comments · Fixed by #18642 or #19049
Closed

Error: invalid memory address or nil pointer dereference #18629

pboguslawski opened this issue Feb 5, 2022 · 6 comments · Fixed by #18642 or #19049
Labels

Comments

@pboguslawski
Copy link
Contributor

Gitea Version

1.16-rc1

Git Version

No response

Operating System

No response

How are you running Gitea?

Compiled from source.

Database

No response

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Description

A single case was caught:

2022/02/05 21:20:50 ...s/context/context.go:377:JSON() [E] Render JSON failed: write tcp giteahostip:3000->clientip:52624: write: connection reset by peer
2022/02/05 21:20:50 ...common/middleware.go:70:1() [E] PANIC: runtime error: invalid memory address or nil pointer dereference
    /usr/lib/go-1.17/src/runtime/panic.go:221 (0x44dc66)
    /usr/lib/go-1.17/src/runtime/signal_unix.go:735 (0x44dc36)
    /src/somepath/gitea-build/modules/context/context.go:201 (0x14d2083)
    /src/somepath/gitea-build/modules/context/context.go:273 (0x14d2ae9)
    /src/somepath/gitea-build/modules/context/context.go:261 (0x14d479b)
    /src/somepath/gitea-build/modules/context/context.go:377 (0x14d477f)
    /src/somepath/gitea-build/routers/api/v1/repo/repo.go:239 (0x1daf584)
    /src/somepath/gitea-build/modules/web/route.go:80 (0x1cb0f66)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77ba4e)
    /pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:442 (0x14c6a15)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77ba4e)
    /src/somepath/gitea-build/modules/web/route.go:144 (0x1cb1a4d)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77ba4e)
    /src/somepath/gitea-build/modules/web/route.go:144 (0x1cb1a4d)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77ba4e)
    /src/somepath/gitea-build/modules/context/api.go:307 (0x14ced5a)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77ba4e)
    /src/somepath/gitea-build/routers/api/v1/api.go:1107 (0x1de2a33)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77ba4e)
    /pkg/mod/gitea.com/go-chi/[email protected]/session.go:257 (0x12cbf3d)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77ba4e)
    /pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:71 (0x14c484c)
    /pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:314 (0x14c61fb)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77ba4e)
    /pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:442 (0x14c6a15)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77ba4e)
    /src/somepath/gitea-build/routers/common/middleware.go:78 (0x1ce80e1)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77ba4e)
    /pkg/mod/github.com/go-chi/chi/[email protected]/middleware/strip.go:30 (0x1ce2bb8)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77ba4e)
    /pkg/mod/github.com/chi-middleware/[email protected]/middleware.go:37 (0x1cdf476)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77ba4e)
    /src/somepath/gitea-build/routers/common/middleware.go:31 (0x1ce7f39)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77ba4e)
    /pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:88 (0x14c4801)
    /src/somepath/gitea-build/modules/web/route.go:328 (0x1cb42ed)
    /usr/lib/go-1.17/src/net/http/server.go:2879 (0x77efba)
    /usr/lib/go-1.17/src/net/http/server.go:1930 (0x77ab27)
    /usr/lib/go-1.17/src/runtime/asm_amd64.s:1581 (0x46ad60)

Screenshots

No response

@zeripath
Copy link
Contributor

zeripath commented Feb 5, 2022

ctx.JSON(http.StatusOK, api.SearchResults{

@zeripath
Copy link
Contributor

zeripath commented Feb 5, 2022

ctx.ServerError("Render JSON failed", err)

ctx.serverErrorInternal(logMsg, logErr)

ctx.HTML(http.StatusInternalServerError, base.TplName("status/500"))

if err := ctx.Render.HTML(ctx.Resp, status, string(name), ctx.Data); err != nil {

@zeripath
Copy link
Contributor

zeripath commented Feb 5, 2022

I don't understand how a nil pointer exception can happen here.

@zeripath
Copy link
Contributor

zeripath commented Feb 5, 2022

Ok I guess we just need to stop attempting to render if the underlying error is connection reset by peer.

@lunny lunny added the type/bug label Feb 6, 2022
zeripath added a commit to zeripath/gitea that referenced this issue Feb 6, 2022
When a net.OpError occurs during rendering the underlying connection is essentially
dead and therefore attempting to render further data will only cause further errors.

Therefore in serverErrorInternal detect if the passed in error is an OpError and
if so do not attempt any further rendering.

Fix go-gitea#18629

Signed-off-by: Andrew Thornton <[email protected]>
6543 pushed a commit that referenced this issue Feb 6, 2022
When a net.OpError occurs during rendering the underlying connection is essentially
dead and therefore attempting to render further data will only cause further errors.

Therefore in serverErrorInternal detect if the passed in error is an OpError and
if so do not attempt any further rendering.

Fix #18629

Signed-off-by: Andrew Thornton <[email protected]>
zeripath added a commit to zeripath/gitea that referenced this issue Feb 6, 2022
…#18642)

Backport go-gitea#18642

When a net.OpError occurs during rendering the underlying connection is essentially
dead and therefore attempting to render further data will only cause further errors.

Therefore in serverErrorInternal detect if the passed in error is an OpError and
if so do not attempt any further rendering.

Fix go-gitea#18629

Signed-off-by: Andrew Thornton <[email protected]>
lunny pushed a commit that referenced this issue Feb 7, 2022
…18645)

Backport #18642

When a net.OpError occurs during rendering the underlying connection is essentially
dead and therefore attempting to render further data will only cause further errors.

Therefore in serverErrorInternal detect if the passed in error is an OpError and
if so do not attempt any further rendering.

Fix #18629

Signed-off-by: Andrew Thornton <[email protected]>
@pboguslawski
Copy link
Contributor Author

Gitea 1.16.1 (built from 3d08e3a, includes fix https://github.com/go-gitea/gitea/pull/18642/files) still throws sometimes:

2022/03/09 22:39:02 ...s/context/context.go:385:JSON() [E] Render JSON failed: write tcp giteahostip:3000->clientip:43562: write: broken pipe
2022/03/09 22:39:02 ...common/middleware.go:70:1() [E] PANIC: runtime error: invalid memory address or nil pointer dereference
    /usr/lib/go-1.17/src/runtime/panic.go:221 (0x44dc66)
    /usr/lib/go-1.17/src/runtime/signal_unix.go:735 (0x44dc36)
    /src/vcs.ib.loc/ib/gitea-build/modules/context/context.go:203 (0x14d24c3)
    /src/vcs.ib.loc/ib/gitea-build/modules/context/context.go:281 (0x14d2f64)
    /src/vcs.ib.loc/ib/gitea-build/modules/context/context.go:263 (0x14d4c1b)
    /src/vcs.ib.loc/ib/gitea-build/modules/context/context.go:385 (0x14d4bff)
    /src/vcs.ib.loc/ib/gitea-build/routers/api/v1/repo/repo.go:239 (0x1dafc84)
    /src/vcs.ib.loc/ib/gitea-build/modules/web/route.go:80 (0x1cb1466)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77bcae)
    /pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:442 (0x14c6e55)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77bcae)
    /src/vcs.ib.loc/ib/gitea-build/modules/web/route.go:144 (0x1cb1f4d)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77bcae)
    /src/vcs.ib.loc/ib/gitea-build/modules/web/route.go:144 (0x1cb1f4d)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77bcae)
    /src/vcs.ib.loc/ib/gitea-build/modules/context/api.go:307 (0x14cf19a)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77bcae)
    /src/vcs.ib.loc/ib/gitea-build/routers/api/v1/api.go:1107 (0x1de3133)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77bcae)
    /pkg/mod/gitea.com/go-chi/[email protected]/session.go:257 (0x12cb91d)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77bcae)
    /pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:71 (0x14c4c8c)
    /pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:314 (0x14c663b)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77bcae)
    /pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:442 (0x14c6e55)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77bcae)
    /src/vcs.ib.loc/ib/gitea-build/routers/common/middleware.go:78 (0x1ce8601)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77bcae)
    /pkg/mod/github.com/go-chi/chi/[email protected]/middleware/strip.go:30 (0x1ce30d8)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77bcae)
    /pkg/mod/github.com/chi-middleware/[email protected]/middleware.go:37 (0x1cdf996)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77bcae)
    /src/vcs.ib.loc/ib/gitea-build/routers/common/middleware.go:31 (0x1ce8459)
    /usr/lib/go-1.17/src/net/http/server.go:2047 (0x77bcae)
    /pkg/mod/github.com/go-chi/chi/[email protected]/mux.go:88 (0x14c4c41)
    /src/vcs.ib.loc/ib/gitea-build/modules/web/route.go:328 (0x1cb47ed)
    /usr/lib/go-1.17/src/net/http/server.go:2879 (0x77f21a)
    /usr/lib/go-1.17/src/net/http/server.go:1930 (0x77ad87)
    /usr/lib/go-1.17/src/runtime/asm_amd64.s:1581 (0x46ad60)

@zeripath
Copy link
Contributor

Well this is irritating.

package main

import (
	"errors"
	"fmt"
	"net"
)

func main() {
	opError := &net.OpError{Op: "write", Net: "", Err: fmt.Errorf("random")}
	fmt.Println(opError)

	fmt.Println(errors.Is(opError, &net.OpError{}))
}

a *net.OpError does not pass errors.Is(err, &net.OpError).

We'll have to try again with just plain type checking because go's errors.Is just doesn't do what it should do.

@zeripath zeripath reopened this Mar 10, 2022
zeripath added a commit to zeripath/gitea that referenced this issue Mar 10, 2022
Unfortunately go-gitea#18642 does not work because a `*net.OpError` does not implement
the `Is` interface to make `errors.Is` work correctly - thus leading to the
irritating conclusion that a `*net.OpError` is not a `*net.OpError`.

Here we keep the `errors.Is` because presumably this will be fixed at
some point in the golang main source code but also we add a simply type
cast to also check.

Fix go-gitea#18629

Signed-off-by: Andrew Thornton <[email protected]>
zeripath added a commit that referenced this issue Mar 10, 2022
…2) (#19049)

Unfortunately #18642 does not work because a `*net.OpError` does not implement
the `Is` interface to make `errors.Is` work correctly - thus leading to the
irritating conclusion that a `*net.OpError` is not a `*net.OpError`.

Here we keep the `errors.Is` because presumably this will be fixed at
some point in the golang main source code but also we add a simply type
cast to also check.

Fix #18629

Signed-off-by: Andrew Thornton <[email protected]>
zeripath added a commit to zeripath/gitea that referenced this issue Mar 10, 2022
…2) (go-gitea#19049)

Backport go-gitea#19049

Unfortunately go-gitea#18642 does not work because a `*net.OpError` does not implement
the `Is` interface to make `errors.Is` work correctly - thus leading to the
irritating conclusion that a `*net.OpError` is not a `*net.OpError`.

Here we keep the `errors.Is` because presumably this will be fixed at
some point in the golang main source code but also we add a simply type
cast to also check.

Fix go-gitea#18629

Signed-off-by: Andrew Thornton <[email protected]>
6543 pushed a commit that referenced this issue Mar 10, 2022
…2) (#19049) (#19056)

Backport #19049

Unfortunately #18642 does not work because a `*net.OpError` does not implement
the `Is` interface to make `errors.Is` work correctly - thus leading to the
irritating conclusion that a `*net.OpError` is not a `*net.OpError`.

Here we keep the `errors.Is` because presumably this will be fixed at
some point in the golang main source code but also we add a simply type
cast to also check.

Fix #18629

Signed-off-by: Andrew Thornton <[email protected]>
Chianina pushed a commit to Chianina/gitea that referenced this issue Mar 28, 2022
…#18642)

When a net.OpError occurs during rendering the underlying connection is essentially
dead and therefore attempting to render further data will only cause further errors.

Therefore in serverErrorInternal detect if the passed in error is an OpError and
if so do not attempt any further rendering.

Fix go-gitea#18629

Signed-off-by: Andrew Thornton <[email protected]>
Chianina pushed a commit to Chianina/gitea that referenced this issue Mar 28, 2022
…2) (go-gitea#19049)

Unfortunately go-gitea#18642 does not work because a `*net.OpError` does not implement
the `Is` interface to make `errors.Is` work correctly - thus leading to the
irritating conclusion that a `*net.OpError` is not a `*net.OpError`.

Here we keep the `errors.Is` because presumably this will be fixed at
some point in the golang main source code but also we add a simply type
cast to also check.

Fix go-gitea#18629

Signed-off-by: Andrew Thornton <[email protected]>
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
3 participants