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

panic log for some http API with negative table id #52012

Closed
lcwangchao opened this issue Mar 22, 2024 · 1 comment · Fixed by #52016
Closed

panic log for some http API with negative table id #52012

lcwangchao opened this issue Mar 22, 2024 · 1 comment · Fixed by #52016
Assignees
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@lcwangchao
Copy link
Collaborator

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

> curl "http://127.0.0.1:10080/db-table/-123"

2. What did you expect to see? (Required)

> curl "http://127.0.0.1:10080/db-table/-123"
[schema:1146]Table which ID = -123 does not exist.

3. What did you see instead (Required)

> curl "http://127.0.0.1:10081/db-table/-123"
curl: (52) Empty reply from server

And a panic log in tidb

2024/03/22 10:42:52 http: panic serving 127.0.0.1:53256: runtime error: index out of range [-123]
goroutine 5202 [running]:
net/http.(*conn).serve.func1()
        /Users/wangchao/.gvm/gos/go1.21.0/src/net/http/server.go:1868 +0x118
panic({0x1081c98c0?, 0x140189ca198?})
        /Users/wangchao/.gvm/gos/go1.21.0/src/runtime/panic.go:920 +0x254
github.com/pingcap/tidb/pkg/infoschema.(*infoSchema).TableByID(0x140059bba00, 0xffffffffffffff85)
        /Users/wangchao/Code/pingcap/tidb/pkg/infoschema/infoschema.go:235 +0xfc
github.com/pingcap/tidb/pkg/server/handler/tikvhandler.DBTableHandler.ServeHTTP({0x1401179e5d0}, {0x10850bac0, 0x140189b6000}, 0x14017be9c00)
        /Users/wangchao/Code/pingcap/tidb/pkg/server/handler/tikvhandler/tikv_handler.go:1805 +0x238
github.com/gorilla/mux.(*Router).ServeHTTP(0x1401142cf00, {0x10850bac0, 0x140189b6000}, 0x14017be9c00)
        /Users/wangchao/.gvm/pkgsets/go1.21.0/global/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x254
net/http.(*ServeMux).ServeHTTP(0x140118b5900, {0x10850bac0, 0x140189b6000}, 0x14017be9a00)
        /Users/wangchao/.gvm/gos/go1.21.0/src/net/http/server.go:2514 +0x160
github.com/pingcap/tidb/pkg/server/internal/util.CorsHandler.ServeHTTP({{0x1084ed0e0, 0x140118b5900}, 0x140007de900}, {0x10850bac0, 0x140189b6000}, 0x14017be9a00)
        /Users/wangchao/Code/pingcap/tidb/pkg/server/internal/util/util.go:219 +0xe0
net/http.serverHandler.ServeHTTP({0x1401142f1d0}, {0x10850bac0, 0x140189b6000}, 0x14017be9a00)
        /Users/wangchao/.gvm/gos/go1.21.0/src/net/http/server.go:2938 +0x2a0
net/http.(*conn).serve(0x140189a4000, {0x108520c18, 0x140189a6050})
        /Users/wangchao/.gvm/gos/go1.21.0/src/net/http/server.go:2009 +0x155c
created by net/http.(*Server).Serve in goroutine 573
        /Users/wangchao/.gvm/gos/go1.21.0/src/net/http/server.go:3086 +0x7f8

4. What is your TiDB version? (Required)

@lcwangchao lcwangchao added type/bug The issue is confirmed as a bug. sig/sql-infra SIG: SQL Infra severity/moderate labels Mar 22, 2024
@lcwangchao
Copy link
Collaborator Author

lcwangchao commented Mar 22, 2024

The reason is that we use % to compute the bucket index.

return int(tableID % bucketCount)

However, if the table id is negative, a negative index will be returned:

func main() {
	// will return -123
	fmt.Println(-123 % 512)
}

https://go.dev/play/p/XtiDd-ZyhWy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant