Don't crash on not working database connection
If the connection to a mongo instance fails, the controller hard crashed like this:
{"level":"error","msg":"Error reading in gNMI subscription paths, can not watch network elements automati
cally: open configs/gNMISubscriptions.txt: no such file or directory","time":"2024-06-06T22:38:20+02:00"}
{"level":"info","msg":"will try to connect to rabbitmq: amqp://guest:guest@localhost:5672/","time":"2024-
06-06T22:38:20+02:00"}
{"level":"info","msg":"Connected to RabbitMQ","time":"2024-06-06T22:38:20+02:00"}
{"level":"info","msg":"Could not connect to database","time":"2024-06-06T22:38:25+02:00"}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x1048fa4b0]
goroutine 1 [running]:
go.mongodb.org/mongo-driver/mongo.newCollection(0x0, {0x104c5f20d, 0xf}, {0x0?, 0x0?, 0x0?})
/Users/aps/go/pkg/mod/go.mongodb.org/mongo-driver@v1.15.0/mongo/collection.go:74 +0xa0
go.mongodb.org/mongo-driver/mongo.(*Database).Collection(...)
/Users/aps/go/pkg/mod/go.mongodb.org/mongo-driver@v1.15.0/mongo/database.go:109
code.fbi.h-da.de/danet/gosdn/controller/topology/nodes.NewDatabaseNodeStore(...)
/Users/aps/code/hda/gosdn/controller/topology/nodes/databaseNodeStore.go:38
code.fbi.h-da.de/danet/gosdn/controller/topology/nodes.NewNodeStore(0x105a6cba0?)
/Users/aps/code/hda/gosdn/controller/topology/nodes/store.go:16 +0x58
code.fbi.h-da.de/danet/gosdn/controller.initialize()
/Users/aps/code/hda/gosdn/controller/controller.go:103 +0xa4
code.fbi.h-da.de/danet/gosdn/controller.Run.func1()
/Users/aps/code/hda/gosdn/controller/controller.go:384 +0x24
sync.(*Once).doSlow(0x7?, 0x140000c2100?)
/usr/local/go/src/sync/once.go:74 +0x100
sync.(*Once).Do(...)
/usr/local/go/src/sync/once.go:65
code.fbi.h-da.de/danet/gosdn/controller.Run({0x1051851f0, 0x140000c8050})
/Users/aps/code/hda/gosdn/controller/controller.go:383 +0x68
code.fbi.h-da.de/danet/gosdn/controller/cmd.init.func1(0x140000ec800?, {0x104c52846?, 0x4?, 0x104c5280a?}
)
/Users/aps/code/hda/gosdn/controller/cmd/root.go:65 +0x48
github.com/spf13/cobra.(*Command).execute(0x105a72800, {0x14000130040, 0x0, 0x0})
/Users/aps/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:983 +0x840
github.com/spf13/cobra.(*Command).ExecuteC(0x105a72800)
/Users/aps/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
/Users/aps/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039
code.fbi.h-da.de/danet/gosdn/controller/cmd.Execute()
/Users/aps/code/hda/gosdn/controller/cmd/root.go:72 +0x2c
main.main()
/Users/aps/code/hda/gosdn/controller/cmd/gosdn/main.go:48 +0x4c
With this change it will gracefully "crash" without the segmentation fault.
{"level":"error","msg":"Error reading in gNMI subscription paths, can not watch network elements automatically: open configs/gNMISubscriptions.txt: no such file or directory","time":"2024-06-06T22:42:58+02:00"}
{"level":"info","msg":"will try to connect to rabbitmq: amqp://guest:guest@localhost:5672/","time":"2024-06-06T22:42:58+02:00"}
{"level":"info","msg":"Connected to RabbitMQ","time":"2024-06-06T22:42:58+02:00"}
{"level":"info","msg":"Could not connect to database","time":"2024-06-06T22:43:03+02:00"}
{"level":"error","msg":"failed to connect to database: server selection error: context deadline exceeded, current topology: { Type: Unknown, Servers: [{ Addr: localhost:27017, Type: Unknown, Last error: dial tcp 127.0.0.1:27017: connect: connection refused }, ] }","time":"2024-06-06T22:43:03+02:00"}
Error: failed to connect to database: server selection error: context deadline exceeded, current topology: { Type: Unknown, Servers: [{ Addr: localhost:27017, Type: Unknown, Last error: dial tcp 127.0.0.1:27017: connect: connection refused }, ] }
Usage:
gosdn [flags]
gosdn [command]
Available Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
version returns information about the controllers version
Flags:
--config string config file (default is ./configs/gosdn.toml)
--csbi-orchestrator string csbi orchestrator address
-h, --help help for gosdn
-l, --log-level string log level 'debug' or 'trace'
--plugin-folder string folder holding all goSDN specific plugins
--plugin-registry string plugin registry address
-s, --security string security level 'secure' or 'insecure'
--socket string port for the controllers gRPC northbound interface
Use "gosdn [command] --help" for more information about a command.
{"level":"error","msg":"failed to connect to database: server selection error: context deadline exceeded, current topology: { Type: Unknown, Servers: [{ Addr: localhost:27017, Type: Unknown, Last error: dial tcp 127.0.0.1:27017: connect: connection refused }, ] }","time":"2024-06-06T22:43:03+02:00"}
Merge request reports
Activity
added componentnucleus prioritylow typebug labels
assigned to @hda1
added 1 commit
- 61a2b75d - Provide mongo and rabbit for legacy unit tests
added 10 commits
-
61a2b75d...3b6cc67b - 3 commits from branch
master
- d68e5442 - Don't crash on not working database connection
- 5c5b8841 - Remove superfluous log output
- 2a82e4a1 - Fix lint error
- 53a86efb - Retry connection
- 9366a28c - Don't use connect() directly
- 2e8b4a2d - Fix lint
- 98ac7dd2 - Provide mongo and rabbit for legacy unit tests
Toggle commit list-
61a2b75d...3b6cc67b - 3 commits from branch
added 8 commits
- 4538b9b6 - Don't crash on not working database connection
- e62ca00f - Remove superfluous log output
- 4d49f4bf - Fix lint error
- bdc71dbf - Retry connection
- 6b8689d6 - Don't use connect() directly
- 31f1382a - Fix lint
- 61a2b75d - Provide mongo and rabbit for legacy unit tests
- e49d5f7b - Merge branch 'no-db-crash' of code.fbi.h-da.de:danet/gosdn into no-db-crash
Toggle commit listadded 1 commit
- e5fbbcda - Only connect to mongoDB if we use the database store mode
reset approvals from @neil.schark by pushing to the branch
added 4 commits
-
499dd0fb...473a3663 - 3 commits from branch
master
- 739d6e49 - Merge branch 'master' into no-db-crash
-
499dd0fb...473a3663 - 3 commits from branch
enabled an automatic merge when the pipeline for 739d6e49 succeeds
Please register or sign in to reply