hasura / hasura/graphql-engine

CLI console crashes when adding datasource if cli is older version

Open
#7,689 0 comments 2 reactions 0 assignees View on GitHub
c/cli c/console estimate/L k/bug t/product-platform
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

When running the cli `v2.0.9` against a server `v2.1.0-beta.1`, and attempting to add a data source, the cli crashes with this error:

> Hasura console is not able to reach your Hasura GraphQL engine instance. Please ensure that your instance is running and the endpoint is configured correctly.

The command line where the console is running will show the following error message:

```
2021/10/15 12:17:53 http: panic serving 127.0.0.1:58622: runtime error: invalid memory address or nil pointer dereference
```

Full Stack trace

```
2021/10/15 12:17:53 http: panic serving 127.0.0.1:58622: runtime error: invalid memory address or nil pointer dereference
goroutine 99 [running]:
net/http.(*conn).serve.func1(0xc000128dc0)
/usr/local/go/src/net/http/server.go:1824 +0x153
panic(0xce9260, 0x43bdd10)
/usr/local/go/src/runtime/panic.go:971 +0x49a
github.com/hasura/graphql-engine/cli/v2/migrate/api.MigrateAPI(0xc0000aa0d0)
/root/graphql-engine/cli/migrate/api/migrate.go:147 +0x28c5
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.(*APIServer).setConfigVersion.func1(0xc0000aa0d0)
/root/graphql-engine/cli/pkg/console/apiserver.go:157 +0xc5
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.(*APIServer).setEC.func1(0xc0000aa0d0)
/root/graphql-engine/cli/pkg/console/apiserver.go:142 +0xb7
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.(*APIServer).setMigrate.func1(0xc0000aa0d0)
/root/graphql-engine/cli/pkg/console/apiserver.go:135 +0xb7
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.(*APIServer).setFilePath.func1(0xc0000aa0d0)
/root/graphql-engine/cli/pkg/console/apiserver.go:150 +0x12b
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.(*APIServer).setLogger.func1(0xc0000aa0d0)
/root/graphql-engine/cli/pkg/console/apiserver.go:173 +0xb7
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.cliProjectUpdateCheck.func1(0xc0000aa0d0)
/root/graphql-engine/cli/pkg/console/apiserver.go:70 +0x72
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc00012c000, 0xc0000aa0d0)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/gin.go:403 +0x2ef
github.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc00012c000, 0x3dce4f8, 0xc000578000, 0xc000196200)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/gin.go:364 +0x155
net/http.serverHandler.ServeHTTP(0xc0002fa000, 0x3dce4f8, 0xc000578000, 0xc000196200)
/usr/local/go/src/net/http/server.go:2887 +0xaa
net/http.(*conn).serve(0xc000128dc0, 0x3dd1f50, 0xc0002e8400)
/usr/local/go/src/net/http/server.go:1952 +0x8cd
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3013 +0x3b8
2021/10/15 12:17:53 http: panic serving 127.0.0.1:53316: runtime error: invalid memory address or nil pointer dereference
goroutine 15 [running]:
net/http.(*conn).serve.func1(0xc000150000)
/usr/local/go/src/net/http/server.go:1824 +0x153
panic(0xce9260, 0x43bdd10)
/usr/local/go/src/runtime/panic.go:971 +0x49a
github.com/hasura/graphql-engine/cli/v2/migrate/api.MigrateAPI(0xc0006f6750)
/root/graphql-engine/cli/migrate/api/migrate.go:147 +0x28c5
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.(*APIServer).setConfigVersion.func1(0xc0006f6750)
/root/graphql-engine/cli/pkg/console/apiserver.go:157 +0xc5
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.(*APIServer).setEC.func1(0xc0006f6750)
/root/graphql-engine/cli/pkg/console/apiserver.go:142 +0xb7
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.(*APIServer).setMigrate.func1(0xc0006f6750)
/root/graphql-engine/cli/pkg/console/apiserver.go:135 +0xb7
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.(*APIServer).setFilePath.func1(0xc0006f6750)
/root/graphql-engine/cli/pkg/console/apiserver.go:150 +0x12b
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.(*APIServer).setLogger.func1(0xc0006f6750)
/root/graphql-engine/cli/pkg/console/apiserver.go:173 +0xb7
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.cliProjectUpdateCheck.func1(0xc0006f6750)
/root/graphql-engine/cli/pkg/console/apiserver.go:70 +0x72
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc00012c000, 0xc0006f6750)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/gin.go:403 +0x2ef
github.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc00012c000, 0x3dce4f8, 0xc0002fa1c0, 0xc00056a000)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/gin.go:364 +0x155
net/http.serverHandler.ServeHTTP(0xc0002fa000, 0x3dce4f8, 0xc0002fa1c0, 0xc00056a000)
/usr/local/go/src/net/http/server.go:2887 +0xaa
net/http.(*conn).serve(0xc000150000, 0x3dd1f50, 0xc0001a0000)
/usr/local/go/src/net/http/server.go:1952 +0x8cd
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3013 +0x3b8
2021/10/15 12:17:53 http: panic serving 127.0.0.1:49949: runtime error: invalid memory address or nil pointer dereference
goroutine 102 [running]:
net/http.(*conn).serve.func1(0xc000280960)
/usr/local/go/src/net/http/server.go:1824 +0x153
panic(0xce9260, 0x43bdd10)
/usr/local/go/src/runtime/panic.go:971 +0x49a
github.com/hasura/graphql-engine/cli/v2/migrate/api.MigrateAPI(0xc0006f6b60)
/root/graphql-engine/cli/migrate/api/migrate.go:147 +0x28c5
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.(*APIServer).setConfigVersion.func1(0xc0006f6b60)
/root/graphql-engine/cli/pkg/console/apiserver.go:157 +0xc5
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.(*APIServer).setEC.func1(0xc0006f6b60)
/root/graphql-engine/cli/pkg/console/apiserver.go:142 +0xb7
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.(*APIServer).setMigrate.func1(0xc0006f6b60)
/root/graphql-engine/cli/pkg/console/apiserver.go:135 +0xb7
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.(*APIServer).setFilePath.func1(0xc0006f6b60)
/root/graphql-engine/cli/pkg/console/apiserver.go:150 +0x12b
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.(*APIServer).setLogger.func1(0xc0006f6b60)
/root/graphql-engine/cli/pkg/console/apiserver.go:173 +0xb7
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/hasura/graphql-engine/cli/v2/pkg/console.cliProjectUpdateCheck.func1(0xc0006f6b60)
/root/graphql-engine/cli/pkg/console/apiserver.go:70 +0x72
github.com/gin-gonic/gin.(*Context).Next(...)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest(0xc00012c000, 0xc0006f6b60)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/gin.go:403 +0x2ef
github.com/gin-gonic/gin.(*Engine).ServeHTTP(0xc00012c000, 0x3dce4f8, 0xc0002fa380, 0xc0005c4600)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/gin.go:364 +0x155
net/http.serverHandler.ServeHTTP(0xc0002fa000, 0x3dce4f8, 0xc0002fa380, 0xc0005c4600)
/usr/local/go/src/net/http/server.go:2887 +0xaa
net/http.(*conn).serve(0xc000280960, 0x3dd1f50, 0xc00058f040)
/usr/local/go/src/net/http/server.go:1952 +0x8cd
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3013 +0x3b8
```

### Version Information

Server Version: 2.1.0-beta.1
CLI Version (for CLI related issue): 2.0.9

### Environment

Tested on locally hosted instance

### What is the expected behaviour?

If cli v2.0.9 is incompatible with server 2.1.0-beta.1, a more descriptive error should be thrown

### Keywords

cli, console, crash

### What is the current behaviour?

As stated above, cli crashes

### How to reproduce the issue?

1. Create a locally hosted project, with server version `v2.1.0-beta.1`

Full instructions with example file

In a new directory, create the following files:

`config.yaml`
```yaml
version: 3
endpoint: http://localhost:8080
```
`.env`
```.env
HASURA_GRAPHQL_ADMIN_SECRET=secret
PG_USERNAME=postgres
PG_PASSWORD=postgres
```
`docker-compose.yml`
```yaml
version: "3.8"
services:
postgres:
image: postgres:13
ports:
- 5432:5432
restart: always
volumes:
- db_data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: ${PG_PASSWORD}
POSTGRES_USER: ${PG_USERNAME}
POSTGRES_DB: postgres
graphql-engine:
image: hasura/graphql-engine:v2.1.0-beta.1
ports:
- "8080:8080"
depends_on:
- "postgres"
- "business-logic"
restart: always
environment:
# documentation on hasura configuration environemtn variables can be found at https://hasura.io/docs/latest/graphql/core/deployment/graphql-engine-flags/reference.html#server-flag-reference
HASURA_GRAPHQL_METADATA_DATABASE_URL: postgres://${PG_USERNAME}:${PG_PASSWORD}@postgres/postgres
# enable the console served by server
HASURA_GRAPHQL_ENABLE_CONSOLE: "false" # set to "false" to disable console
# enable debugging mode. It is recommended to disable this in production
HASURA_GRAPHQL_DEV_MODE: "true"
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
# uncomment next line to set an admin secret
HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET}
PG_DATABASE_URL: postgres://${PG_USERNAME}:${PG_PASSWORD}@postgres/postgres
volumes:
db_data:
```
Run `docker compose up -d`

You example setup should be ready

2. install cli version `v2.0.9` (latests as of this writing) with `hasura update-cli --version v2.0.9`
3. Run the console with `hasura console`
4. Attempt to connect a data source with the `PG_DATABASE_URL` environment variable:
5. You will see the reported error, and the cli will crash
![image](https://user-images.githubusercontent.com/25712958/137525701-7071d834-eba0-49ed-bbfe-c5ed94bd4d85.png)

### Any possible solutions?

Update your cli, by running `hasura update-cli --version v2.1.0-beta.1`
Ideally, future version of the cli would warn against this and give a more human-friendly message.

Contributor guide

Open the contributing guide

Research direction

Start with cli/migrate/api/migrate.go at line 147 and reproduce the crash using config.yaml, .env, and docker-compose.yml with server v2.1.0-beta.1 and CLI v2.0.9. Trace the datasource-add request from the console and verify that an incompatible version reports a descriptive error instead of panicking.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go, postgresql
Domain
cli, databases
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.