influxdata / influxdata/influxdb

Panic if "every" field is omitted in NotificationRulesAPI.createNotificationRule

Open
#23,088 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
31.7k
Forks
3.7k
Avg merge
13h 37m
Merged PRs (30d)
8

Description

Steps to reproduce:
We are using the InfluxDB JavaScript Client.

For instance:

    create_result = await notificationRulesAPI.createNotificationRule({
        body: {
            type: 'http',
            endpointID: user.notificationEndpointId,
            name: "E-mail Notification Rule",
            description: "Notification rule for sending e-mail to SendGrid.",
            orgID: user.orgId,
            status: user.sendDeviceEmails === 'email' ? 'active' : 'inactive',
            statusRules: statusRules
        }});

causes a panic. "every" is listed as an optional field, but including it fixes the issue:

    create_result = await notificationRulesAPI.createNotificationRule({
        body: {
            type: 'http',
            endpointID: user.notificationEndpointId,
            name: "E-mail Notification Rule",
            description: "Notification rule for sending e-mail to SendGrid.",
            every: '1h',
            orgID: user.orgId,
            status: user.sendDeviceEmails === 'email' ? 'active' : 'inactive',
            statusRules: statusRules
        }});

fixes the issue.

Expected behavior:
"every" is listed as an optional field, but omitting it causes a kernel panic. If it is intended to be necessary, an enlightening error like "missing required field: every" should be returned. If it is not intended to be necessary, then the issue should be fixed.

Actual behavior:
The server shows msg="a panic has occurred" log_id=0ZP2H~~l000 handler=panic error="/api/v2/notificationRules: runtime error: invalid memory address or nil pointer dereference".

Environment info:

  • System info: Linux 5.15.15-76051515-generic x86_64
  • InfluxDB version: influxdb:latest (2.1.1)
  • Other relevant environment details: Docker version 20.10.7, build f0df350

Config:

docker run -p 8086:8086 \
           -e DOCKER_INFLUXDB_INIT_USERNAME=influx_dev_user \
           -e DOCKER_INFLUXDB_INIT_PASSWORD=influx_not_secure \
           -e DOCKER_INFLUXDB_INIT_ORG=required_but_unused_org \
           -e DOCKER_INFLUXDB_INIT_BUCKET=required_but_unused_bucket \
           -e DOCKER_INFLUXDB_INIT_MODE=setup \
           -e DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=not_secure_admin_token \
           influxdb:latest

Logs:

ts=2022-02-01T07:35:09.397252Z lvl=error msg="a panic has occurred" log_id=0ZP2H~~l000 handler=panic error="/api/v2/notificationRules: runtime error: invalid memory address or nil pointer dereference" stacktrace="goroutine 4595 [running]:\nruntime/debug.Stack()\n\t/home/circleci/.tools/go/src/runtime/debug/stack.go:24 +0x65\ngithub.com/influxdata/influxdb/v2/http.baseHandler.panic({{0x4058600, 0xc0026caae0}}, {0x4077400, 0xc00141d460}, 0x0, {0x3c52600, 0x53e34d0})\n\t/home/circleci/go/src/github.com/influxdata/influxdb/http/router.go:96 +0x1b3\ngithub.com/influxdata/httprouter.(*Router).recv(0xc00279b170, {0x4077400, 0xc00141d460}, 0xaa45ab)\n\t/home/circleci/go/pkg/mod/github.com/influxdata/httprouter@v1.3.1-0.20191122104820-ee83e2772f69/router.go:361 +0x5e\npanic({0x3c52600, 0x53e34d0})\n\t/home/circleci/.tools/go/src/runtime/panic.go:1038 +0x215\ngithub.com/influxdata/influxdb/v2/notification/rule.increaseDur(0x0)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/notification/rule/rule.go:258 +0x34\ngithub.com/influxdata/influxdb/v2/notification/rule.(*Base).generateFluxASTStatuses(0xc000669260)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/notification/rule/rule.go:296 +0x3d\ngithub.com/influxdata/influxdb/v2/notification/rule.(*HTTP).generateFluxASTBody(0xc000669260, 0xc001177dc0)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/notification/rule/http.go:54 +0x287\ngithub.com/influxdata/influxdb/v2/notification/rule.(*HTTP).GenerateFluxAST(0xc000669260, 0xc000754648)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/notification/rule/http.go:30 +0x45\ngithub.com/influxdata/influxdb/v2/notification/rule.(*HTTP).GenerateFlux(0xc000669260, {0x40f6120, 0xc0005fe500})\n\t/home/circleci/go/src/github.com/influxdata/influxdb/notification/rule/http.go:25 +0x36\ngithub.com/influxdata/influxdb/v2/notification/rule/service.(*RuleService).createNotificationTask(0xc000676d20, {0x40a6bc0, 0xc000964810}, {{0x40fd088, 0xc000669260}, {0xc0008b38f8, 0x23abcb8}})\n\t/home/circleci/go/src/github.com/influxdata/influxdb/notification/rule/service/service.go:163 +0xc5\ngithub.com/influxdata/influxdb/v2/notification/rule/service.(*RuleService).CreateNotificationRule(0xc000676d20, {0x40a6bc0, 0xc000964810}, {{0x40fd088, 0xc000669260}, {0xc0008b38f8, 0x23abcb8}}, 0x8d905ced0228000)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/notification/rule/service/service.go:122 +0x1a5\ngithub.com/influxdata/influxdb/v2/task/backend/middleware.(*CoordinatingNotificationRuleStore).CreateNotificationRule(0xc0012f8b40, {0x40a6bc0, 0xc000964810}, {{0x40fd088, 0xc000669260}, {0xc0008b38f8, 0xc000754a68}}, 0xa5b86b)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/task/backend/middleware/notification_middleware.go:39 +0x70\ngithub.com/influxdata/influxdb/v2/authorizer.(*NotificationRuleStore).CreateNotificationRule(0xc0027916e0, {0x40a6bc0, 0xc000964810}, {{0x40fd088, 0xc000669260}, {0xc0008b38f8, 0x10}}, 0x10)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/authorizer/notification_rule.go:57 +0xe2\ngithub.com/influxdata/influxdb/v2/http.(*NotificationRuleHandler).handlePostNotificationRule(0xc00279b200, {0x4077400, 0xc00141d460}, 0xc0005fe400)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/http/notification_rule.go:594 +0x37d\nnet/http.HandlerFunc.ServeHTTP(0x7f22dcb48e60, {0x4077400, 0xc00141d460}, 0x7f23071f3a68)\n\t/home/circleci/.tools/go/src/net/http/server.go:2046 +0x2f\ngithub.com/influxdata/influxdb/v2/http.(*proxyHandler).ServeHTTP(0xc0013fe340, {0x4077400, 0xc00141d460}, 0x90)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/http/proxy_handler.go:33 +0x68\ngithub.com/influxdata/httprouter.(*Router).Handler.func1({0x4077400, 0xc00141d460}, 0x3c4d440, {0x0, 0x3b69c00, 0xc0013e1240})\n\t/home/circleci/go/pkg/mod/github.com/influxdata/httprouter@v1.3.1-0.20191122104820-ee83e2772f69/router.go:325 +0x2c4\ngithub.com/influxdata/httprouter.(*Router).ServeHTTP(0xc00279b170, {0x4077400, 0xc00141d460}, 0xc0005fe300)\n\t/home/circleci/go/pkg/mod/github.com/influxdata/httprouter@v1.3.1-0.20191122104820-ee83e2772f69/router.go:453 +0x4c3\ngithub.com/go-chi/chi.(*Mux).Mount.func1({0x4077400, 0xc00141d460}, 0xc0005fe300)\n\t/home/circleci/go/pkg/mod/github.com/go-chi/chi@v4.1.0+incompatible/mux.go:298 +0x13b\nnet/http.HandlerFunc.ServeHTTP(0x3c2d5a0, {0x4077400, 0xc00141d460}, 0xc0011a0920)\n\t/home/circleci/.tools/go/src/net/http/server.go:2046 +0x2f\ngithub.com/go-chi/chi.(*Mux).routeHTTP(0xc0026f9800, {0x4077400, 0xc00141d460}, 0xc0005fe300)\n\t/home/circleci/go/pkg/mod/github.com/go-chi/chi@v4.1.0+incompatible/mux.go:431 +0x1f9\nnet/http.HandlerFunc.ServeHTTP(0xc000964240, {0x4077400, 0xc00141d460}, 0xc0007550b8)\n\t/home/circleci/.tools/go/src/net/http/server.go:2046 +0x2f\ngithub.com/influxdata/influxdb/v2/kit/transport/http.SetCORS.func1({0x4077400, 0xc00141d460}, 0xc0005fe300)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/kit/transport/http/middleware.go:36 +0x308\nnet/http.HandlerFunc.ServeHTTP(0xe, {0x4077400, 0xc00141d460}, 0x203000)\n\t/home/circleci/.tools/go/src/net/http/server.go:2046 +0x2f\ngithub.com/go-chi/chi/middleware.StripSlashes.func1({0x4077400, 0xc00141d460}, 0xc0005fe300)\n\t/home/circleci/go/pkg/mod/github.com/go-chi/chi@v4.1.0+incompatible/middleware/strip.go:25 +0x102\nnet/http.HandlerFunc.ServeHTTP(0xc000964240, {0x4077400, 0xc00141d460}, 0x30)\n\t/home/circleci/.tools/go/src/net/http/server.go:2046 +0x2f\ngithub.com/influxdata/influxdb/v2/kit/transport/http.SkipOptions.func1({0x4077400, 0xc00141d460}, 0xc0005fe300)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/kit/transport/http/middleware.go:81 +0xb9\nnet/http.HandlerFunc.ServeHTTP(0xc000964330, {0x4077400, 0xc00141d460}, 0xc000755238)\n\t/home/circleci/.tools/go/src/net/http/server.go:2046 +0x2f\ngithub.com/influxdata/influxdb/v2/http.panicMW.func1.1({0x4077400, 0xc00141d460}, 0xc0007552f0)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/http/router.go:126 +0x9b\nnet/http.HandlerFunc.ServeHTTP(0x90, {0x4077400, 0xc00141d460}, 0x1000000023ca01f)\n\t/home/circleci/.tools/go/src/net/http/server.go:2046 +0x2f\ngithub.com/go-chi/chi.(*Mux).ServeHTTP(0xc0026f9800, {0x4077400, 0xc00141d460}, 0xc0005fe300)\n\t/home/circleci/go/pkg/mod/github.com/go-chi/chi@v4.1.0+incompatible/mux.go:70 +0x40e\ngithub.com/influxdata/influxdb/v2/kit/feature.(*Handler).ServeHTTP(0xc0027da240, {0x4077400, 0xc00141d460}, 0xc0005fe200)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/kit/feature/middleware.go:43 +0x3c2\ngithub.com/influxdata/influxdb/v2/http.(*AuthenticationHandler).ServeHTTP(0xc0026b9110, {0x4077400, 0xc00141d460}, 0xc0005fe100)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/http/authentication_middleware.go:127 +0x467\ngithub.com/influxdata/influxdb/v2/kit/transport/http.SetCORS.func1({0x4077400, 0xc00141d460}, 0xc0005fe100)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/kit/transport/http/middleware.go:36 +0x308\nnet/http.HandlerFunc.ServeHTTP(0xc000964240, {0x4077400, 0xc00141d460}, 0xc0011a0921)\n\t/home/circleci/.tools/go/src/net/http/server.go:2046 +0x2f\ngithub.com/influxdata/influxdb/v2/kit/transport/http.SkipOptions.func1({0x4077400, 0xc00141d460}, 0xc0005fe100)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/kit/transport/http/middleware.go:81 +0xb9\nnet/http.HandlerFunc.ServeHTTP(0x33d8a90, {0x4077400, 0xc00141d460}, 0x18)\n\t/home/circleci/.tools/go/src/net/http/server.go:2046 +0x2f\ngithub.com/influxdata/influxdb/v2/http.(*PlatformHandler).ServeHTTP(0xc0027da340, {0x4077400, 0xc00141d460}, 0xc0005fe100)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/http/platform_handler.go:81 +0x1d2\ngithub.com/go-chi/chi.(*Mux).Mount.func1({0x4077400, 0xc00141d460}, 0xc0005fe100)\n\t/home/circleci/go/pkg/mod/github.com/go-chi/chi@v4.1.0+incompatible/mux.go:298 +0x13b\nnet/http.HandlerFunc.ServeHTTP(0x203000, {0x4077400, 0xc00141d460}, 0xc00141d440)\n\t/home/circleci/.tools/go/src/net/http/server.go:2046 +0x2f\ngithub.com/influxdata/influxdb/v2/kit/transport/http.Metrics.func1.1({0x407c1d0, 0xc000668fc0}, 0xc0005fe100)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/kit/transport/http/middleware.go:66 +0x1e2\nnet/http.HandlerFunc.ServeHTTP(0xc0004c1830, {0x407c1d0, 0xc000668fc0}, 0x7f22d9a28318)\n\t/home/circleci/.tools/go/src/net/http/server.go:2046 +0x2f\ngithub.com/influxdata/influxdb/v2/kit/transport/http.Trace.func1.1({0x407c1d0, 0xc000668fc0}, 0x2)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/kit/transport/http/middleware.go:106 +0x30c\nnet/http.HandlerFunc.ServeHTTP(0xc0027e0180, {0x407c1d0, 0xc000668fc0}, 0xc000654c78)\n\t/home/circleci/.tools/go/src/net/http/server.go:2046 +0x2f\ngithub.com/go-chi/chi.(*ChainHandler).ServeHTTP(0x3c2d5a0, {0x407c1d0, 0xc000668fc0}, 0xc0013f4bd5)\n\t/home/circleci/go/pkg/mod/github.com/go-chi/chi@v4.1.0+incompatible/chain.go:31 +0x2c\ngithub.com/go-chi/chi.(*Mux).routeHTTP(0xc0027dc180, {0x407c1d0, 0xc000668fc0}, 0xc0005fe000)\n\t/home/circleci/go/pkg/mod/github.com/go-chi/chi@v4.1.0+incompatible/mux.go:431 +0x1f9\nnet/http.HandlerFunc.ServeHTTP(0x88, {0x407c1d0, 0xc000668fc0}, 0x90)\n\t/home/circleci/.tools/go/src/net/http/server.go:2046 +0x2f\ngithub.com/influxdata/influxdb/v2/http.(*AddHeader).Middleware.func1({0x407c1d0, 0xc000668fc0}, 0x53c4e01)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/http/handler.go:102 +0x77\nnet/http.HandlerFunc.ServeHTTP(0x40a6b18, {0x407c1d0, 0xc000668fc0}, 0x53c4e90)\n\t/home/circleci/.tools/go/src/net/http/server.go:2046 +0x2f\ngithub.com/go-chi/chi.(*Mux).ServeHTTP(0xc0027dc180, {0x407c1d0, 0xc000668fc0}, 0xc000531f00)\n\t/home/circleci/go/pkg/mod/github.com/go-chi/chi@v4.1.0+incompatible/mux.go:86 +0x3c2\ngithub.com/influxdata/influxdb/v2/http.(*Handler).ServeHTTP(0x0, {0x407c1d0, 0xc000668fc0}, 0x40)\n\t/home/circleci/go/src/github.com/influxdata/influxdb/http/handler.go:166 +0x2f\nnet/http.serverHandler.ServeHTTP({0x4072558}, {0x407c1d0, 0xc000668fc0}, 0xc000531f00)\n\t/home/circleci/.tools/go/src/net/http/server.go:2878 +0x43b\nnet/http.(*conn).serve(0xc0006d2b40, {0x40a6bc0, 0xc0027e03f0})\n\t/home/circleci/.tools/go/src/net/http/server.go:1929 +0xb08\ncreated by net/http.(*Server).Serve\n\t/home/circleci/.tools/go/src/net/http/server.go:3033 +0x4e8\n"

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the omission through the /api/v2/notificationRules endpoint, then trace the request through http/notification_rule.go and notification/rule/service.go. Inspect increaseDur and generateFluxASTStatuses in notification/rule/rule.go, along with notification/rule/http.go; done means omitting every no longer causes a nil-pointer panic and produces the intended validation or creation result.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, javascript
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.