Skip to content

Commit

Permalink
node: create neo-go client with a meaningful context
Browse files Browse the repository at this point in the history
Context is an important part of neo-go client's lifecycle, it is passed at
creation stage. Do not use `context.Background`, use a general application one
instead.

Signed-off-by: Pavel Karpy <[email protected]>
  • Loading branch information
carpawell committed Aug 7, 2024
1 parent 39dd720 commit d9d0613
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 4 additions & 1 deletion cmd/neofs-node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ var persistateSideChainLastBlockKey = []byte("side_chain_last_processed_block")

func initCfg(appCfg *config.Config) *cfg {
c := &cfg{}
ctx, ctxCancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)

err := c.readConfig(appCfg)
if err != nil {
Expand Down Expand Up @@ -542,7 +543,8 @@ func initCfg(appCfg *config.Config) *cfg {
fatalOnErr(err)

c.internals = internals{
ctx: context.Background(),
ctx: ctx,
ctxCancel: ctxCancel,
cfgReader: appCfg,
internalErr: make(chan error, 10), // We only need one error, but we can have multiple senders.
wg: new(sync.WaitGroup),
Expand Down Expand Up @@ -639,6 +641,7 @@ func initBasics(c *cfg, key *keys.PrivateKey, stateStorage *state.PersistentStor
}

cli, err := client.New(key,
client.WithContext(c.internals.ctx),
client.WithDialTimeout(c.applicationConfiguration.morph.dialTimeout),
client.WithLogger(c.log),
client.WithAutoSidechainScope(),
Expand Down
5 changes: 0 additions & 5 deletions cmd/neofs-node/main.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package main

import (
"context"
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"

"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
"github.com/nspcc-dev/neofs-node/misc"
Expand Down Expand Up @@ -125,8 +122,6 @@ func initApp(c *cfg) {
initLocalStorage(c)
initAndLog(c, "gRPC", initGRPC)

c.ctx, c.ctxCancel = signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)

initAndLog(c, "container", initContainerService)
initAndLog(c, "storage engine", func(c *cfg) {
fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Open())
Expand Down

0 comments on commit d9d0613

Please sign in to comment.