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: interface conversion: interface is []uint8, not int64 #2349

Closed
Ingramz opened this issue Jan 6, 2016 · 29 comments
Closed

PANIC: interface conversion: interface is []uint8, not int64 #2349

Ingramz opened this issue Jan 6, 2016 · 29 comments
Labels
💊 bug Something isn't working status: needs feedback Tell me more about it
Milestone

Comments

@Ingramz
Copy link

Ingramz commented Jan 6, 2016

After adding PAM as an authentication method, I am immediately greeted with a blank page and following panic.

Installed from source with pam tag using this guide. Using Debian 8 if that matters.

[Macaron] PANIC: interface conversion: interface is []uint8, not int64
/usr/local/go/src/runtime/panic.go:423 (0x42ba09)
/usr/local/go/src/runtime/iface.go:221 (0x40d5f0)
/home/git/go/src/github.com/gogits/gogs/models/login.go:111 (0x548dd2)
        (*LoginSource).BeforeSet: switch LoginType((*val).(int64)) {
/home/git/go/src/github.com/go-xorm/xorm/session.go:1656 (0x6e8da5)
        (*Session)._row2Bean: b.BeforeSet(key, Cell(scanResults[ii].(*interface{})))
/home/git/go/src/github.com/go-xorm/xorm/session.go:1625 (0x6e8783)
        (*Session).rows2Beans: err := session._row2Bean(rows, fields, fieldsCount, bean, &dataStruct, table)
/home/git/go/src/github.com/go-xorm/xorm/session.go:1365 (0x6e4617)
        (*Session).Find: return session.rows2Beans(rawRows, fields, fieldsCount, table, newElemFunc, sliceValueSetFunc)
/home/git/go/src/github.com/go-xorm/xorm/engine.go:1347 (0x6b1389)
        (*Engine).Find: return session.Find(beans, condiBeans...)
/home/git/go/src/github.com/gogits/gogs/models/login.go:191 (0x549768)
        LoginSources: return auths, x.Find(&auths)
/home/git/go/src/github.com/gogits/gogs/routers/admin/auths.go:32 (0x7f69fc)
        Authentications: ctx.Data["Sources"], err = models.LoginSources()
/usr/local/go/src/runtime/asm_amd64.s:437 (0x45cbce)
/usr/local/go/src/reflect/value.go:432 (0x87fe4a)
/usr/local/go/src/reflect/value.go:300 (0x87eb11)
/home/git/go/src/github.com/go-macaron/inject/inject.go:117 (0xb28a42)
        (*injector).Invoke: return reflect.ValueOf(f).Call(in), nil
/home/git/go/src/gopkg.in/macaron.v1/context.go:113 (0x74b8d7)
        (*Context).run: vals, err := c.Invoke(c.handler())
/home/git/go/src/gopkg.in/macaron.v1/context.go:104 (0x74b7bc)
        (*Context).Next: c.run()
/home/git/go/src/github.com/go-macaron/session/session.go:186 (0x698f84)
        Sessioner.func1: ctx.Next()
/usr/local/go/src/runtime/asm_amd64.s:437 (0x45cbce)
/usr/local/go/src/reflect/value.go:432 (0x87fe4a)
/usr/local/go/src/reflect/value.go:300 (0x87eb11)
/home/git/go/src/github.com/go-macaron/inject/inject.go:117 (0xb28a42)
        (*injector).Invoke: return reflect.ValueOf(f).Call(in), nil
/home/git/go/src/gopkg.in/macaron.v1/context.go:113 (0x74b8d7)
        (*Context).run: vals, err := c.Invoke(c.handler())
/home/git/go/src/gopkg.in/macaron.v1/context.go:104 (0x74b7bc)
        (*Context).Next: c.run()
/home/git/go/src/gopkg.in/macaron.v1/recovery.go:161 (0x760ca2)
        Recovery.func1: c.Next()
/usr/local/go/src/runtime/asm_amd64.s:437 (0x45cbce)
/usr/local/go/src/reflect/value.go:432 (0x87fe4a)
/usr/local/go/src/reflect/value.go:300 (0x87eb11)
/home/git/go/src/github.com/go-macaron/inject/inject.go:117 (0xb28a42)
        (*injector).Invoke: return reflect.ValueOf(f).Call(in), nil
/home/git/go/src/gopkg.in/macaron.v1/context.go:113 (0x74b8d7)
        (*Context).run: vals, err := c.Invoke(c.handler())
/home/git/go/src/gopkg.in/macaron.v1/context.go:104 (0x74b7bc)
        (*Context).Next: c.run()
/home/git/go/src/gopkg.in/macaron.v1/logger.go:40 (0x75f8ee)
        Logger.func1: ctx.Next()
/usr/local/go/src/runtime/asm_amd64.s:437 (0x45cbce)
/usr/local/go/src/reflect/value.go:432 (0x87fe4a)
/usr/local/go/src/reflect/value.go:300 (0x87eb11)
/home/git/go/src/github.com/go-macaron/inject/inject.go:117 (0xb28a42)
        (*injector).Invoke: return reflect.ValueOf(f).Call(in), nil
/home/git/go/src/gopkg.in/macaron.v1/context.go:113 (0x74b8d7)
        (*Context).run: vals, err := c.Invoke(c.handler())
/home/git/go/src/gopkg.in/macaron.v1/router.go:184 (0x762424)
        (*Router).Handle.func1: c.run()
/home/git/go/src/gopkg.in/macaron.v1/router.go:286 (0x758d9d)
        (*Router).ServeHTTP: h(rw, req, p)
/home/git/go/src/gopkg.in/macaron.v1/macaron.go:175 (0x750cda)
        (*Macaron).ServeHTTP: m.Router.ServeHTTP(rw, req)
/usr/local/go/src/net/http/server.go:1862 (0x65065e)
/usr/local/go/src/net/http/server.go:1361 (0x64de4e)
/usr/local/go/src/runtime/asm_amd64.s:1721 (0x45ef41)
[Macaron] Completed /admin/auths 500 Internal Server Error in 7.649728ms

@bitbyt3r
Copy link

bitbyt3r commented Jan 6, 2016

I am seeing this same issue adding any type of external authentication.

@unknwon
Copy link
Member

unknwon commented Jan 7, 2016

Thanks your feedback!

But I can't reproduce this locally, can you provide more details on steps?

@unknwon unknwon added status: needs reproduce Wait, how did that happen? status: needs feedback Tell me more about it labels Jan 7, 2016
@unknwon unknwon added this to the 0.9.0 milestone Jan 7, 2016
@xiegeo
Copy link

xiegeo commented Jan 7, 2016

@Ingramz @bitbyt3r Which databases are you using?

@Ingramz
Copy link
Author

Ingramz commented Jan 7, 2016

@xiegeo mysql 5.5.46

@Ingramz
Copy link
Author

Ingramz commented Jan 7, 2016

Here's a way to reproduce this using docker.

Install from docker official debian:latest with port 3000 exposed if needed, so you can access it from your host machine

enter that container's shell and run:

adduser --disabled-login --gecos 'Gogs' git

debconf-set-selections <<CONFIG
mysql-server-5.5 mysql-server/root_password password change_me
mysql-server-5.5 mysql-server/root_password_again password change_me
CONFIG

apt-get update
apt-get install -y --force-yes mysql-server wget git
service mysql start
mysql -uroot -pchange_me -e "create database if not exists gogs;"

su - git
mkdir local
wget https://storage.googleapis.com/golang/go1.5.2.linux-amd64.tar.gz
tar -C /home/git/local -xzf go1.5.2.linux-amd64.tar.gz

echo 'export GOROOT=$HOME/local/go' >> $HOME/.bashrc
echo 'export GOPATH=$HOME/go' >> $HOME/.bashrc
echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> $HOME/.bashrc
source $HOME/.bashrc

go get -u github.com/gogits/gogs
cd $GOPATH/src/github.com/gogits/gogs
go build

./gogs web

Now browse that address (for me it was localhost:3000)

install as usual (I disabled self-registration and created an user), mysql password is change_me

go to /admin/auths

add a new source, eg pam with some dummy data

as soon as you click add, panic will occur

@unknwon
Copy link
Member

unknwon commented Jan 7, 2016

Thanks @Ingramz ,

not talking adding PAM first, the way you compile Gogs does not support PAM anyway...

@Ingramz
Copy link
Author

Ingramz commented Jan 7, 2016

@unknwon I did it like that on purpose, because the issue isn't related to PAM directly.

@unknwon
Copy link
Member

unknwon commented Jan 7, 2016

@Ingramz does add a dummy LDAP auth source panic too?

@Ingramz
Copy link
Author

Ingramz commented Jan 7, 2016

@unknwon yes. Adding any auth source does that.

@unknwon
Copy link
Member

unknwon commented Jan 7, 2016

OK... can you dump the database table login_source see what is the value of filed type?

@Ingramz
Copy link
Author

Ingramz commented Jan 7, 2016

Added LDAP this time.

mysql> select type from gogs.login_source;
+------+
| type |
+------+
|    2 |
+------+
1 row in set (0.00 sec)

mysql> describe gogs.login_source;
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | bigint(20)   | NO   | PRI | NULL    | auto_increment |
| type       | int(11)      | YES  |     | NULL    |                |
| name       | varchar(255) | YES  | UNI | NULL    |                |
| is_actived | tinyint(1)   | NO   |     | 0       |                |
| cfg        | text         | YES  |     | NULL    |                |
| created    | datetime     | YES  |     | NULL    |                |
| updated    | datetime     | YES  |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)

@unknwon
Copy link
Member

unknwon commented Jan 7, 2016

Thanks.

Suppose you're using the master version,

it would be very helpful if you can add a line right after this line:

fmt.Println(*val)

Then recompile and restart Gogs.

@Ingramz
Copy link
Author

Ingramz commented Jan 7, 2016

I'm getting [50] which is ASCII code for 2

@unknwon unknwon added 💊 bug Something isn't working and removed status: needs feedback Tell me more about it labels Jan 7, 2016
@unknwon
Copy link
Member

unknwon commented Jan 7, 2016

Thanks. Though I don't know why it gets []int8, but I think I know how to convert :trollface:

@Ingramz
Copy link
Author

Ingramz commented Jan 7, 2016

Also /admin/users/new and /admin/users/1 are failing to load for the same reason, seems like they all enumerate the login_source in some way.

@unknwon
Copy link
Member

unknwon commented Jan 7, 2016

OK... seems to be a bigger problem.

What if you use compiled binary (not compile by yourself)?

@Ingramz
Copy link
Author

Ingramz commented Jan 7, 2016

originally I tried packages from https://packager.io/gh/pkgr/gogs, these had the same problem.

@unknwon
Copy link
Member

unknwon commented Jan 7, 2016

By compiled binary, I mean https://dl.gogs.io/ , packager.io is no difference from compiling yourself.

@Ingramz
Copy link
Author

Ingramz commented Jan 7, 2016

gogs_v0.8.10_linux_amd64.tar.gz is working perfectly

@unknwon
Copy link
Member

unknwon commented Jan 11, 2016

Hi @Ingramz , can you help test develop branch again?

@unknwon unknwon added status: needs feedback Tell me more about it and removed status: needs reproduce Wait, how did that happen? labels Jan 11, 2016
@Ingramz
Copy link
Author

Ingramz commented Jan 11, 2016

@unknwon I tried and that won't work for 2 reasons. []int8 should be []uint8 and if you simply take the first value of the byte array, you'll get the ASCII integer value, which for digits is in range 48-57. So it would give PANIC: unrecognized login source type: 4 from https://github.com/gogits/gogs/blob/develop/models/login.go#L130 where it constructs a string from *val - in this case the '4' was actually intval 52

Any idea as to why it gives a different type for different systems on that interface, perhaps an issue with ORM?

@unknwon
Copy link
Member

unknwon commented Jan 11, 2016

Any idea as to why it gives a different type for different systems on that interface, perhaps an issue with ORM?

Actually I don't know why MySQL driver could return different type in different system... I believe it supposed to be in a unified format. Yeah, maybe it's ORM's problem.

unknwon added a commit that referenced this issue Jan 11, 2016
@unknwon
Copy link
Member

unknwon commented Jan 11, 2016

Just pushed another fix to develop.

@Ingramz
Copy link
Author

Ingramz commented Jan 11, 2016

@unknwon now seems to be working. I added also a trace for int64 and now I see that on some pages (like when logging in) it uses int64 and for instance on /admin/auths it uses []uint8, very strange.

@unknwon
Copy link
Member

unknwon commented Jan 11, 2016

@Ingramz great... quite hard to trace the original bug location.

@Ingramz
Copy link
Author

Ingramz commented Jan 11, 2016

Only difference I can see is that in stack trace. https://www.diffchecker.com/ldcgb7fr - this is what is done differently. I have very little experience with go and xorm, so I'll just leave it here. The current solution is good enough to work around the problem.

@unknwon
Copy link
Member

unknwon commented Jan 11, 2016

Very helpful!

I think the driver may behave differently for Get (get on record) and Find (get all records), this could explain a bit why the type is not the same based on my experience with Go, though I think they should be same when they return from ORM.

@unknwon
Copy link
Member

unknwon commented Jan 25, 2016

Close as fixed.

@unknwon unknwon closed this as completed Jan 25, 2016
@lei314121077
Copy link

this is redis process data error , get key is interface type but your process is []int8 case

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💊 bug Something isn't working status: needs feedback Tell me more about it
Projects
None yet
Development

No branches or pull requests

5 participants