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

Sending a invalid null type makes the request goroutine panic #2420

Closed
louis-paul opened this issue Apr 24, 2015 · 3 comments
Closed

Sending a invalid null type makes the request goroutine panic #2420

louis-paul opened this issue Apr 24, 2015 · 3 comments

Comments

@louis-paul
Copy link

Hi!

This bug was found on the v0.9.0-rc27 version, installed from pre-compiled .deb packages on Ubuntu x64. It occurs when the client tries to push points. If a field in the fields part of a point has an invalid type, such as a JSON null value instead of Golang's string zero value (the empty string), the unmarshalling of the request payload fails. This error causes the request goroutine to panic and the server to return a HTTP 500 Internal Server Error code. This may be an invalid request for InfluxDB, but it would be more appropriate for the server to return a 400 Bad Request code and not to crash.

Here is the JSON used (via a standard POST request to the write API) to reproduce the bug:

{  
  "database":"testdb",
  "points":[  
     {  
        "name":"request.new",
        "fields":{  
           "url":"http:\/\/www.example.com",
           "ip":"192.168.56.1",
           "country":null,
           "referer":null
        },
        "tags":{  
           "name":"request.new"
        }
     }
  ]
}

And here is the stack trace from /var/log/influxdb/influxd.log after a POST to /write:

[srvr] 2015/04/24 20:34:27 http: panic serving 158.199.249.58:50873: unsupported value type during encode fields: <nil>
goroutine 14121954 [running]:
net/http.func·011()
    /root/.gvm/gos/go1.4.2/src/net/http/server.go:1130 +0xbb
github.com/influxdb/influxdb.(*FieldCodec).EncodeFields(0xc208170e20, 0xc208346930, 0x0, 0x0, 0x0, 0x0, 0x0)
    /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/database.go:849 +0x8e3
github.com/influxdb/influxdb.func·036(0x0, 0x0)
    /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/server.go:1883 +0x75d
github.com/influxdb/influxdb.(*Server).WriteSeries(0xc208062a00, 0xc208170c10, 0xd, 0x9ad100, 0x7, 0xc208093c40, 0x1, 0x1, 0x0, 0x0, ...)
    /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/server.go:1901 +0xa80
github.com/influxdb/influxdb/httpd.(*Handler).serveWrite(0xc208160e60, 0x7fc8a17798f0, 0xc20835e440, 0xc2083b3ad0, 0x0)
    /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/httpd/handler.go:534 +0xdf5
github.com/influxdb/influxdb/httpd.*Handler.(github.com/influxdb/influxdb/httpd.serveWrite)·fm(0x7fc8a17798f0, 0xc20835e440, 0xc2083b3ad0, 0x0)
    /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/httpd/handler.go:124 +0x4f
github.com/influxdb/influxdb/httpd.func·004(0x7fc8a17798f0, 0xc20835e440, 0xc2083b3ad0)
    /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/httpd/handler.go:905 +0x77
net/http.HandlerFunc.ServeHTTP(0xc20835e140, 0x7fc8a17798f0, 0xc20835e440, 0xc2083b3ad0)
    /root/.gvm/gos/go1.4.2/src/net/http/server.go:1265 +0x41
github.com/influxdb/influxdb/httpd.func·005(0x7fc8a17798f0, 0xc20835e440, 0xc2083b3ad0)
    /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/httpd/handler.go:949 +0xd9
net/http.HandlerFunc.ServeHTTP(0xc208170850, 0x7fc8a17798f0, 0xc20835e440, 0xc2083b3ad0)
    /root/.gvm/gos/go1.4.2/src/net/http/server.go:1265 +0x41
github.com/influxdb/influxdb/httpd.func·006(0x7fc8a17798f0, 0xc20835e440, 0xc2083b3ad0)
    /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/httpd/handler.go:965 +0xb0
net/http.HandlerFunc.ServeHTTP(0xc20835e160, 0x7fc8a17798f0, 0xc20835e440, 0xc2083b3ad0)
    /root/.gvm/gos/go1.4.2/src/net/http/server.go:1265 +0x41
github.com/influxdb/influxdb/httpd.func·007(0x7fc8a17798f0, 0xc20835e440, 0xc2083b3ad0)
    /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/httpd/handler.go:998 +0x31a
net/http.HandlerFunc.ServeHTTP(0xc208170890, 0x7fc8a17798f0, 0xc20835e440, 0xc2083b3ad0)
    /root/.gvm/gos/go1.4.2/src/net/http/server.go:1265 +0x41
github.com/influxdb/influxdb/httpd.func·008(0x7fc8a17798f0, 0xc20835e440, 0xc2083b3ad0)
    /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/httpd/handler.go:1008 +0x179
net/http.HandlerFunc.ServeHTTP(0xc2081708b0, 0x7fc8a17798f0, 0xc20835e440, 0xc2083b3ad0)
    /root/.gvm/gos/go1.4.2/src/net/http/server.go:1265 +0x41
github.com/influxdb/influxdb/httpd.func·009(0x7fc8a17798f0, 0xc20835e420, 0xc2083b3ad0)
    /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/httpd/handler.go:1016 +0x123
net/http.HandlerFunc.ServeHTTP(0xc20835e180, 0x7fc8a17798f0, 0xc20835e420, 0xc2083b3ad0)
    /root/.gvm/gos/go1.4.2/src/net/http/server.go:1265 +0x41
github.com/influxdb/influxdb/httpd.func·010(0x7fc8a17790e0, 0xc208434b40, 0xc2083b3ad0)
    /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/httpd/handler.go:1026 +0x12c
net/http.HandlerFunc.ServeHTTP(0xc20835e1a0, 0x7fc8a17790e0, 0xc208434b40, 0xc2083b3ad0)
    /root/.gvm/gos/go1.4.2/src/net/http/server.go:1265 +0x41
github.com/bmizerany/pat.(*PatternServeMux).ServeHTTP(0xc2080382e8, 0x7fc8a17790e0, 0xc208434b40, 0xc2083b3ad0)
    /root/.gvm/pkgsets/go1.4.2/global/src/github.com/bmizerany/pat/mux.go:109 +0x21c
github.com/influxdb/influxdb/httpd.(*Handler).ServeHTTP(0xc208160e60, 0x7fc8a17790e0, 0xc208434b40, 0xc2083b3ad0)
    /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/httpd/handler.go:189 +0x4a
main.(*Handler).serveAPI(0xc20808e220, 0x7fc8a17790e0, 0xc208434b40, 0xc2083b3ad0)
    /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/cmd/influxd/handler.go:150 +0x1f5
main.(*Handler).ServeHTTP(0xc20808e220, 0x7fc8a17790e0, 0xc208434b40, 0xc2083b3ad0)
    /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/cmd/influxd/handler.go:70 +0x556
net/http.serverHandler.ServeHTTP(0xc20800c5a0, 0x7fc8a17790e0, 0xc208434b40, 0xc2083b3ad0)
    /root/.gvm/gos/go1.4.2/src/net/http/server.go:1703 +0x19a
net/http.(*conn).serve(0xc208434a00)
    /root/.gvm/gos/go1.4.2/src/net/http/server.go:1204 +0xb57
created by net/http.(*Server).Serve
    /root/.gvm/gos/go1.4.2/src/net/http/server.go:1751 +0x35e
[http] 2015/04/24 20:34:27 158.199.249.58 - - [24/Apr/2015:20:34:27 +0000] POST /write?db=testdb&time_precision=s&u=usr&p=pwd HTTP/1.1 500 62 - - 4d36bda3-eac1-11e4-9941-000000000000 161.472µs

The part that crashes the server is "country":null, "referer":null, which worked after replacing it by "country":"", "referer":"".

otoolep added a commit that referenced this issue Apr 25, 2015
otoolep added a commit that referenced this issue Apr 25, 2015
@otoolep
Copy link
Contributor

otoolep commented Apr 25, 2015

Thanks @louis-paul -- fixed by PR2429.

@louis-paul
Copy link
Author

Great! Keep up the good work!

otoolep added a commit that referenced this issue Apr 26, 2015
@contentfree
Copy link

Just received this in rc32 so it looks like it's not completely fixed (or maybe regressed…).

Stacktrace:

panic: unsupported value type during encode fields: <nil>

goroutine 37 [running]:
github.com/influxdb/influxdb/tsdb.(*FieldCodec).EncodeFields(0xc2081624a0, 0xc20815acf0, 0x0, 0x0, 0x0, 0x0, 0x0)
  /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/tsdb/shard.go:573 +0x8e3
github.com/influxdb/influxdb/tsdb.(*Shard).WritePoints(0xc208070600, 0xc208110950, 0x1, 0x1, 0x0, 0x0)
  /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/tsdb/shard.go:142 +0x427
github.com/influxdb/influxdb/tsdb.(*Store).WriteToShard(0xc20808d740, 0x3, 0xc208110950, 0x1, 0x1, 0x0, 0x0)
  /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/tsdb/store.go:256 +0xf7
github.com/influxdb/influxdb/cluster.func·002(0x3, 0x1, 0xc208110950, 0x1, 0x1)
  /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/cluster/points_writer.go:213 +0xfc
created by github.com/influxdb/influxdb/cluster.(*PointsWriter).writeToShard
  /root/.gvm/pkgsets/go1.4.2/global/src/github.com/influxdb/influxdb/cluster/points_writer.go:243 +0x2fc

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

No branches or pull requests

3 participants