Skip to content

runtime error: slice bounds out of range in packets.go #36

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

Closed
timnash opened this issue Mar 5, 2013 · 18 comments
Closed

runtime error: slice bounds out of range in packets.go #36

timnash opened this issue Mar 5, 2013 · 18 comments
Assignees
Labels

Comments

@timnash
Copy link

timnash commented Mar 5, 2013

Trying to ApacheBench test a basic page created with Go, and I get this error:

2013/03/05 23:27:03 http: panic serving ipaddress:58369: runtime error: slice bounds out of range
/usr/local/go/src/pkg/net/http/server.go:589 (0x43eb1b)
        _func_004: buf.Write(debug.Stack())
/usr/local/go/src/pkg/runtime/proc.c:1443 (0x410aab)
        panic: reflect·call(d->fn, d->args, d->siz);
/usr/local/go/src/pkg/runtime/runtime.c:128 (0x411577)
        panicstring: runtime·panic(err);
/usr/local/go/src/pkg/runtime/runtime.c:91 (0x411448)
        panicslice: runtime·panicstring("slice bounds out of range");
/usr/local/go/src/pkg/github.com/Go-SQL-Driver/MySQL/packets.go:133 (0x44b2a6)
        com/Go-SQL-Driver/MySQL.(*mysqlConn).readInitPacket: mc.cipher = append(mc.cipher, data[pos:pos+12]...)
/usr/local/go/src/pkg/github.com/Go-SQL-Driver/MySQL/driver.go:46 (0x44a38a)
        com/Go-SQL-Driver/MySQL.(*mysqlDriver).Open: err = mc.readInitPacket()
/usr/local/go/src/pkg/database/sql/sql.go:248 (0x4435bd)
        (*DB).conn: return db.driver.Open(db.dsn)
/usr/local/go/src/pkg/database/sql/sql.go:310 (0x443b10)
        (*DB).prepare: ci, err := db.conn()
/usr/local/go/src/pkg/database/sql/sql.go:295 (0x443a33)
        (*DB).Prepare: stmt, err = db.prepare(query)
/usr/local/go/src/pkg/database/sql/sql.go:380 (0x444493)
        (*DB).Query: stmt, err := db.Prepare(query)
/myfolder/test.go:13 (0x400cd0)
        wwwHandler: result, e := db.Query("SELECT * FROM s WHERE sid=?",sid)
/myfolder/test.go:35 (0x401406)
        _func_001: wwwHandler(w, r, db)
/usr/local/go/src/pkg/net/http/server.go:703 (0x432964)
        HandlerFunc.ServeHTTP: f(w, r)
/usr/local/go/src/pkg/net/http/server.go:941 (0x4337b8)
        (*ServeMux).ServeHTTP: mux.handler(r).ServeHTTP(w, r)
/usr/local/go/src/pkg/net/http/server.go:669 (0x432777)
        (*conn).serve: handler.ServeHTTP(w, w.req)
/usr/local/go/src/pkg/runtime/proc.c:271 (0x40ebb1)
        goexit: runtime·goexit(void)

Here's my code:

package main

import (
    "fmt"
    "net/http"
    "database/sql"
    _ "github.com/Go-SQL-Driver/MySQL"
)

func wwwHandler(w http.ResponseWriter, r *http.Request, db *sql.DB) {
    for i := 0; i < 10; i++ {
        sid := 1
        result, e := db.Query("SELECT * FROM s WHERE sid=?",sid)
        if e != nil {
            panic(e.Error())
        }
        result.Next()
        var resultsid, created, posted, title, above_the_fold, below_the_fold sql.NullString
        var draft_or_final bool
        err := result.Scan(&resultsid,&created,&posted,&title,&above_the_fold,&below_the_fold,&draft_or_final)
        if err != nil {
            panic(err.Error())
        }
        fmt.Fprintf(w, "%s%s%s%s%s",resultsid.String,created.String,title.String,above_the_fold.String,below_the_fold.String)   
    }
}

func main() {
    db, e := sql.Open("mysql", "username:password@/dbname")
    if e != nil {
        panic(e.Error())
    }   
    defer db.Close()
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        wwwHandler(w, r, db)
    })  
    http.ListenAndServe(":80",nil)  
}
@julienschmidt
Copy link
Member

Which MySQL server version are you using?
This seems to be highly related to the fix for Issue #35

@timnash
Copy link
Author

timnash commented Mar 6, 2013

mysql Ver 14.14 Distrib 5.5.29, for debian-linux-gnu (x86_64) using readline 6.2

@julienschmidt
Copy link
Member

Can you reproduce the error?

If yes, can you please add fmt.Println(len(data)-pos, data[pos-11]) to packets.go:134 and post the output?

@julienschmidt
Copy link
Member

Sorry, place it before line 133 please. Otherwise it will panic before the line is reached.

@timnash
Copy link
Author

timnash commented Mar 6, 2013

2013/03/06 02:48:01 http: panic serving ipaddress:39134: runtime error: slice bounds out of range
/usr/local/go/src/pkg/net/http/server.go:589 (0x43ea74)
        _func_004: buf.Write(debug.Stack())
/usr/local/go/src/pkg/runtime/proc.c:1443 (0x410a04)
        panic: reflect·call(d->fn, d->args, d->siz);
/usr/local/go/src/pkg/runtime/runtime.c:128 (0x4114d0)
        panicstring: runtime·panic(err);
/usr/local/go/src/pkg/runtime/runtime.c:91 (0x4113a1)
        panicslice: runtime·panicstring("slice bounds out of range");
/usr/local/go/src/pkg/github.com/Go-SQL-Driver/MySQL/packets.go:133 (0x44b1ff)
        com/Go-SQL-Driver/MySQL.(*mysqlConn).readInitPacket: fmt.Println(len(data)-pos, data[pos-11])
/usr/local/go/src/pkg/github.com/Go-SQL-Driver/MySQL/driver.go:46 (0x44a2e3)
        com/Go-SQL-Driver/MySQL.(*mysqlDriver).Open: err = mc.readInitPacket()
/usr/local/go/src/pkg/database/sql/sql.go:248 (0x443516)
        (*DB).conn: return db.driver.Open(db.dsn)
/usr/local/go/src/pkg/database/sql/sql.go:310 (0x443a69)
        (*DB).prepare: ci, err := db.conn()
/usr/local/go/src/pkg/database/sql/sql.go:295 (0x44398c)
        (*DB).Prepare: stmt, err = db.prepare(query)
/usr/local/go/src/pkg/database/sql/sql.go:380 (0x4443ec)
        (*DB).Query: stmt, err := db.Prepare(query)
/myfolder/test.go:13 (0x400cd0)
        wwwHandler: result, e := db.Query("SELECT * FROM s WHERE sid=?",sid)
/myfolder/test.go:35 (0x40135f)
        _func_001: wwwHandler(w, r, db)
/usr/local/go/src/pkg/net/http/server.go:703 (0x4328bd)
        HandlerFunc.ServeHTTP: f(w, r)
/usr/local/go/src/pkg/net/http/server.go:941 (0x433711)
        (*ServeMux).ServeHTTP: mux.handler(r).ServeHTTP(w, r)
/usr/local/go/src/pkg/net/http/server.go:669 (0x4326d0)
        (*conn).serve: handler.ServeHTTP(w, w.req)
/usr/local/go/src/pkg/runtime/proc.c:271 (0x40eb0a)
        goexit: runtime·goexit(void)

@timnash
Copy link
Author

timnash commented Mar 6, 2013

It only happens with multiple concurrent connections. Before it couldn't handle more than one, but now it handled up to 5 before it panicked. The previous output was from

ab -n 100 -c 10 

@julienschmidt
Copy link
Member

Okay... this time fmt.Println(pos, len(data)) at line 121 ( before if len(data) > pos {) please.
Otherwise I'm running out of ideas what could cause this...

@julienschmidt
Copy link
Member

Or even better: fmt.Println(pos, len(data), data[pos:])

@timnash
Copy link
Author

timnash commented Mar 6, 2013

2013/03/06 02:59:20 http: panic serving ipaddress:41704: runtime error: slice bounds out of range
/usr/local/go/src/pkg/net/http/server.go:589 (0x43ea74)
        _func_004: buf.Write(debug.Stack())
/usr/local/go/src/pkg/runtime/proc.c:1443 (0x410a04)
        panic: reflect·call(d->fn, d->args, d->siz);
/usr/local/go/src/pkg/runtime/runtime.c:128 (0x4114d0)
        panicstring: runtime·panic(err);
/usr/local/go/src/pkg/runtime/runtime.c:91 (0x4113a1)
        panicslice: runtime·panicstring("slice bounds out of range");
/usr/local/go/src/pkg/github.com/Go-SQL-Driver/MySQL/packets.go:133 (0x44b1ff)
        com/Go-SQL-Driver/MySQL.(*mysqlConn).readInitPacket: // which is not documented but seems to work.
/usr/local/go/src/pkg/github.com/Go-SQL-Driver/MySQL/driver.go:46 (0x44a2e3)
        com/Go-SQL-Driver/MySQL.(*mysqlDriver).Open: err = mc.readInitPacket()
/usr/local/go/src/pkg/database/sql/sql.go:248 (0x443516)
        (*DB).conn: return db.driver.Open(db.dsn)
/usr/local/go/src/pkg/database/sql/sql.go:310 (0x443a69)
        (*DB).prepare: ci, err := db.conn()
/usr/local/go/src/pkg/database/sql/sql.go:295 (0x44398c)
        (*DB).Prepare: stmt, err = db.prepare(query)
/usr/local/go/src/pkg/database/sql/sql.go:380 (0x4443ec)
        (*DB).Query: stmt, err := db.Prepare(query)
/myfolder/test.go:13 (0x400cd0)
        wwwHandler: result, e := db.Query("SELECT * FROM s WHERE sid=?",sid)
/myfolder/test.go:35 (0x40135f)
        _func_001: wwwHandler(w, r, db)
/usr/local/go/src/pkg/net/http/server.go:703 (0x4328bd)
        HandlerFunc.ServeHTTP: f(w, r)
/usr/local/go/src/pkg/net/http/server.go:941 (0x433711)
        (*ServeMux).ServeHTTP: mux.handler(r).ServeHTTP(w, r)
/usr/local/go/src/pkg/net/http/server.go:669 (0x4326d0)
        (*conn).serve: handler.ServeHTTP(w, w.req)
/usr/local/go/src/pkg/runtime/proc.c:271 (0x40eb0a)
        goexit: runtime·goexit(void)

@julienschmidt
Copy link
Member

Huh? This trace says it panicked on a comment.
I guess that actually the precompiled package is executed. Please delete the Go-SQL-Driver folder which should be located in your $GOROOT/pkg/linux_amd64/github.com/.
Then run this again. This should give a lot output in your stdout / log.

@timnash
Copy link
Author

timnash commented Mar 6, 2013

Heh. Sorry, still new to Go. I used "go build", thought that would recompile.

Here's the new output (it's repeating because of the concurrent requests, not sure where one ends and another begins):


35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 91 62 98 81 80 126 72 47 78 123 68 126 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 36 99 73 33 104 108 99 44 77 36 103 93 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 52 72 77 42 42 51 98 114 56 95 88 119 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 99 103 89 107 45 58 125 43 87 86 41 104 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 116 114 95 102 99 60 67 123 98 89 118 105 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 86 126 57 64 115 69 61 65 109 38 113 42 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 121 56 70 56 39 88 104 34 107 118 50 52 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 59 116 87 56 80 106 70 94 39 69 100 72 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 87 91 71 46 82 48 58 111 67 62 79 81 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 87 117 103 38 35 123 100 98 64 86 112 83 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 67 104 98 50 115 107 66 71 124 92 57 68 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
35 21
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 62 117 85 43 113 122 52 48 52 83 38 97 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 37 48 94 107 124 81 96 107 122 66 123 101 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 34 91 39 75 37 118 71 61 60 84 114 97 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 34 66 101 88 105 41 44 67 73 41 44 67 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 96 69 116 61 110 55 101 118 68 48 97 119 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 40 107 102 61 62 93 61 86 120 123 35 56 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 126 101 91 121 110 60 33 46 98 38 50 105 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 118 110 69 76 49 77 112 108 78 33 88 118 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 53 51 64 43 82 60 115 81 124 60 86 121 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 78 98 36 41 65 76 58 123 35 54 38 91 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 119 95 87 118 105 48 79 123 66 116 68 54 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 76 43 51 91 81 101 43 67 78 61 40 79 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 57 48 37 103 90 108 47 70 81 68 64 83 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 120 39 83 79 114 113 95 106 116 42 112 118 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 47 45 52 94 93 56 64 119 88 53 60 107 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 45 85 70 61 63 99 84 93 86 117 109 65 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 50 112 93 98 86 101 119 75 78 37 106 106 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 73 64 67 113 50 65 50 117 121 126 47 108 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 83 33 72 41 51 100 33 115 69 58 52 55 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 96 66 101 87 100 111 36 96 59 68 34 124 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 90 76 78 35 97 65 95 61 82 99 124 103 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 86 79 105 65 75 52 99 115 61 113 70 70 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 83 56 90 62 103 108 105 75 121 66 123 100 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 110 44 46 67 71 121 79 91 91 56 67 43 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 65 112 49 63 40 76 39 121 80 98 123 103 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 71 49 93 96 76 60 40 82 68 63 79 77 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 56 40 92 121 109 56 107 51 91 79 93 99 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 121 104 122 80 94 104 111 116 120 125 46 102 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 107 74 113 120 43 102 66 85 103 39 43 63 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 42 64 66 107 116 38 91 122 116 86 49 51 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 40 109 107 84 68 53 123 48 119 45 115 125 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 98 36 44 80 47 54 100 115 55 86 43 113 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 68 90 118 101 116 56 89 58 84 118 117 107 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 36 58 56 72 67 86 100 118 71 60 54 60 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 51 97 111 46 50 82 40 108 106 77 38 114 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 97 106 112 115 114 98 117 70 61 60 85 121 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 89 68 40 55 125 52 41 110 110 97 119 86 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 76 100 52 115 105 55 114 92 86 120 120 114 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 52 90 75 72 104 81 63 37 58 53 58 99 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 54 81 119 36 74 42 48 81 41 117 55 78 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 66 79 71 83 78 108 85 68 53 121 38 76 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 42 75 121 66 123 101 103 85 83 35 83 87 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 115 50 61 122 113 70 76 40 36 120 83 117 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 83 41 110 114 111 86 66 37 52 113 96 110 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 47 73 95 38 60 61 92 54 58 95 79 78 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 45 89 90 54 62 116 79 108 83 58 103 120 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 108 50 81 36 91 33 48 110 91 90 52 53 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 118 90 66 119 82 116 113 93 90 47 120 50 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 35 76 57 116 95 95 62 88 34 62 81 93 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 100 57 45 116 38 90 117 94 88 125 47 110 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 92 91 50 39 107 102 64 77 66 66 99 77 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 68 35 123 101 105 96 39 63 72 45 68 78 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 43 103 73 117 50 54 88 56 79 102 51 104 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 98 40 63 69 124 96 77 63 51 34 79 74 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 82 98 118 76 85 73 78 44 46 68 76 47 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 93 108 43 43 57 123 35 55 46 124 75 64 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 38 105 97 45 88 83 119 125 47 111 97 121 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 113 103 52 105 55 113 89 73 63 65 105 107 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 115 35 79 68 73 33 104 103 77 45 53 100 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 43 45 61 46 108 87 77 93 106 126 90 41 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 72 97 48 104 61 57 69 45 82 54 84 39 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 91 114 79 114 111 85 62 118 87 50 51 72 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 77 122 66 117 74 79 47 62 40 77 45 56 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 37 112 38 104 92 115 77 103 64 72 40 45 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 82 51 69 64 83 95 98 80 74 96 37 55 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21
40 91 [8 2 0 15 128 21 0 0 0 0 0 0 0 0 0 0 61 55 60 101 106 100 54 34 66 105 106 88 0 109 121 115 113 108 95 110 97 116 105 118 101 95 112 97 115 115 119 111 114 100 0]
35 21

julienschmidt added a commit that referenced this issue Mar 6, 2013
@julienschmidt
Copy link
Member

Okay I found the reason. Delete the current source and run go get github.com/Go-SQL-Driver/MySQL.

But I bet the result doesn't make you happy 😕

@ghost ghost assigned julienschmidt Mar 6, 2013
@timnash
Copy link
Author

timnash commented Mar 6, 2013

Now I get

2013/03/06 04:44:28 http: panic serving ipaddress:43688: runtime error: invalid memory address or nil pointer dereference
/usr/local/go/src/pkg/net/http/server.go:589 (0x43ea74)
        _func_004: buf.Write(debug.Stack())
/usr/local/go/src/pkg/runtime/proc.c:1443 (0x410a04)
        panic: reflect·call(d->fn, d->args, d->siz);
/usr/local/go/src/pkg/runtime/runtime.c:128 (0x4114d0)
        panicstring: runtime·panic(err);
/usr/local/go/src/pkg/runtime/thread_linux.c:199 (0x414322)
        sigpanic: runtime·panicstring("invalid memory address or nil pointer dereference");
/usr/local/go/src/pkg/database/sql/sql.go:911 (0x4473fc)
        (*Rows).Next: if rs.closed {
/myfolder/test.go:17 (0x400d10)
        wwwHandler: result.Next()
/myfolder/test.go:35 (0x40135f)
        _func_001: wwwHandler(w, r, db)
/usr/local/go/src/pkg/net/http/server.go:703 (0x4328bd)
        HandlerFunc.ServeHTTP: f(w, r)
/usr/local/go/src/pkg/net/http/server.go:941 (0x433711)
        (*ServeMux).ServeHTTP: mux.handler(r).ServeHTTP(w, r)
/usr/local/go/src/pkg/net/http/server.go:669 (0x4326d0)
        (*conn).serve: handler.ServeHTTP(w, w.req)
/usr/local/go/src/pkg/runtime/proc.c:271 (0x40eb0a)
        goexit: runtime·goexit(void)

An bug in the database/sql package?

@julienschmidt
Copy link
Member

this is the reason for the panic -> result.Next(). result is nil I guess
db.Query(...) should have returned an error.


One other thing:
Use either a for loop (for rows.Next() { ... }) or something like this:

if rows.Next() {
     // whatever
} else {
     // catch error with rows.Err()
}
rows.Close() // <- don't forget this if you are not iterating over ALL results

@timnash
Copy link
Author

timnash commented Mar 6, 2013

Thanks for the help!

@julienschmidt
Copy link
Member

No panics anymore?

@timnash
Copy link
Author

timnash commented Mar 6, 2013

Now I'm getting panics from the http server, but everything seems great with SQL.

@julienschmidt
Copy link
Member

Just comment on this issue if there are further problems

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants