vulpemventures / ocean

:ocean: Elements/Liquid wallet daemon
MIT License
5 stars 7 forks source link

Aborting request during grpc call SelectUtxos panics #69

Open tiero opened 6 months ago

tiero commented 6 months ago

The panic happens when I stop a process that has an open TCP channel during a gRPC request with ocean.

DEBU[0014] account service: start listening to utxo channel for account bip84-account4 
DEBU[0014] account service: start listening to tx channel for account bip84-account4 
DEBU[0016] gRPC method: /ocean.v1.WalletService/Status  
DEBU[0016] gRPC method: /ocean.v1.WalletService/GetInfo 
DEBU[0017] gRPC method: /ocean.v1.AccountService/DeriveAddresses 
DEBU[0017] wallet repository: publish event WalletAccountAddressesDerived 
DEBU[0017] scanner: start watching address 4'/0/484 for account bip84-account4 
DEBU[0017] gRPC method: /ocean.v1.AccountService/DeriveChangeAddresses 
DEBU[0017] wallet repository: publish event WalletAccountAddressesDerived 
DEBU[0017] scanner: start watching address 4'/1/948 for account bip84-account4 
DEBU[0017] gRPC method: /ocean.v1.AccountService/DeriveChangeAddresses 
DEBU[0017] wallet repository: publish event WalletAccountAddressesDerived 
DEBU[0017] scanner: start watching address 4'/1/949 for account bip84-account4 
DEBU[0017] gRPC method: /ocean.v1.TransactionService/SelectUtxos 
DEBU[0120] profiler: total allocated: 384.166GB, heap allocated: 86.295GB, allocated objects count: 1334482679, freed objects count: 770890483 
DEBU[0120] profiler: num of go routines: 96             
DEBU[0191] gRPC method: /ocean.v1.WalletService/Status  
DEBU[0191] gRPC method: /ocean.v1.WalletService/GetInfo 
DEBU[0192] gRPC method: /ocean.v1.AccountService/DeriveAddresses 
DEBU[0192] wallet repository: publish event WalletAccountAddressesDerived 
DEBU[0192] scanner: start watching address 4'/0/485 for account bip84-account4 
DEBU[0192] gRPC method: /ocean.v1.AccountService/DeriveChangeAddresses 
DEBU[0192] wallet repository: publish event WalletAccountAddressesDerived 
DEBU[0192] scanner: start watching address 4'/1/950 for account bip84-account4 
DEBU[0192] gRPC method: /ocean.v1.AccountService/DeriveChangeAddresses 
DEBU[0192] wallet repository: publish event WalletAccountAddressesDerived 
DEBU[0192] scanner: start watching address 4'/1/951 for account bip84-account4 
DEBU[0192] gRPC method: /ocean.v1.TransactionService/SelectUtxos 
panic: runtime error: slice bounds out of range [:-1]

goroutine 63231 [running]:
github.com/vulpemventures/ocean/internal/infrastructure/coin-selector/smallest-subset.getCombination({0x1400b8f5000, 0x27, 0x40}, 0x1, 0x103024420?)
        /Users/tiero/projects/vulpem/ocean/internal/infrastructure/coin-selector/smallest-subset/selector.go:157 +0x2c0
github.com/vulpemventures/ocean/internal/infrastructure/coin-selector/smallest-subset.getCombination({0x1400b8f5000, 0x27, 0x40}, 0x2, 0x103024420?)
        /Users/tiero/projects/vulpem/ocean/internal/infrastructure/coin-selector/smallest-subset/selector.go:155 +0x1ec
github.com/vulpemventures/ocean/internal/infrastructure/coin-selector/smallest-subset.getCombination({0x1400b8f5000, 0x27, 0x40}, 0x3, 0x103024420?)
        /Users/tiero/projects/vulpem/ocean/internal/infrastructure/coin-selector/smallest-subset/selector.go:155 +0x1ec
github.com/vulpemventures/ocean/internal/infrastructure/coin-selector/smallest-subset.getBestCombination({0x1400b8f5000, 0x27, 0x40}, 0x2540be400)
        /Users/tiero/projects/vulpem/ocean/internal/infrastructure/coin-selector/smallest-subset/selector.go:119 +0x84
github.com/vulpemventures/ocean/internal/infrastructure/coin-selector/smallest-subset.selectUtxos(0x1401cfa4300?, {0x14e964f8200, 0x27, 0x102c69fc0?})
        /Users/tiero/projects/vulpem/ocean/internal/infrastructure/coin-selector/smallest-subset/selector.go:71 +0xc8
github.com/vulpemventures/ocean/internal/infrastructure/coin-selector/smallest-subset.(*selector).SelectUtxos(0x103085200?, {0x14e964f8000?, 0x2e, 0x40}, 0x2540be400, {0x14e92422a80, 0x40})
        /Users/tiero/projects/vulpem/ocean/internal/infrastructure/coin-selector/smallest-subset/selector.go:46 +0x210
github.com/vulpemventures/ocean/internal/core/application.(*TransactionService).SelectUtxos(0x14000445b40, {0x1031d0d88, 0x14e9361e360}, {0x1401cae15b8?, 0x1400019b0e0?}, {0x14e92422a80, 0x40}, 0x10247cc90?, 0x0?)
        /Users/tiero/projects/vulpem/ocean/internal/core/application/transaction_service.go:114 +0x10c
github.com/vulpemventures/ocean/internal/interfaces/grpc/handler.(*transaction).SelectUtxos(0x140001b4a80, {0x1031d0d88, 0x14e9361e360}, 0x141fd5c32c0)
        /Users/tiero/projects/vulpem/ocean/internal/interfaces/grpc/handler/transaction.go:59 +0x260
github.com/vulpemventures/ocean/api-spec/protobuf/gen/go/ocean/v1._TransactionService_SelectUtxos_Handler.func1({0x1031d0d88, 0x14e9361e360}, {0x103148200?, 0x141fd5c32c0})
        /Users/tiero/projects/vulpem/ocean/api-spec/protobuf/gen/go/ocean/v1/transaction_grpc.pb.go:340 +0x74
github.com/vulpemventures/ocean/internal/interfaces/grpc/interceptor.unaryLogger({0x1031d0d88, 0x14e9361e360}, {0x103148200, 0x141fd5c32c0}, 0x10389f6a0?, 0x14e920c0b28)
        /Users/tiero/projects/vulpem/ocean/internal/interfaces/grpc/interceptor/logger.go:17 +0x9c
github.com/vulpemventures/ocean/internal/interfaces/grpc.(*service).start.UnaryInterceptor.ChainUnaryServer.func2.1.1({0x1031d0d88?, 0x14e9361e360?}, {0x103148200?, 0x141fd5c32c0?})
        /Users/tiero/go/pkg/mod/github.com/grpc-ecosystem/go-grpc-middleware@v1.3.0/chain.go:25 +0x40
github.com/vulpemventures/ocean/internal/interfaces/grpc.(*service).start.UnaryInterceptor.ChainUnaryServer.func2({0x1031d0d88, 0x14e9361e360}, {0x103148200, 0x141fd5c32c0}, 0x1401ce5aa38?, 0x102ce4b44?)
        /Users/tiero/go/pkg/mod/github.com/grpc-ecosystem/go-grpc-middleware@v1.3.0/chain.go:34 +0xb8
github.com/vulpemventures/ocean/api-spec/protobuf/gen/go/ocean/v1._TransactionService_SelectUtxos_Handler({0x10317da80?, 0x140001b4a80}, {0x1031d0d88, 0x14e9361e360}, 0x14e9361c700, 0x1400066d3e0)
        /Users/tiero/projects/vulpem/ocean/api-spec/protobuf/gen/go/ocean/v1/transaction_grpc.pb.go:342 +0x12c
google.golang.org/grpc.(*Server).processUnaryRPC(0x14000288b40, {0x1031d5aa0, 0x14bde8ecd00}, 0x1477c6686c0, 0x1400066df20, 0x1037ef058, 0x0)
        /Users/tiero/go/pkg/mod/google.golang.org/grpc@v1.53.0/server.go:1336 +0xaec
google.golang.org/grpc.(*Server).handleStream(0x14000288b40, {0x1031d5aa0, 0x14bde8ecd00}, 0x1477c6686c0, 0x0)
        /Users/tiero/go/pkg/mod/google.golang.org/grpc@v1.53.0/server.go:1704 +0x7cc
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        /Users/tiero/go/pkg/mod/google.golang.org/grpc@v1.53.0/server.go:965 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 56607
        /Users/tiero/go/pkg/mod/google.golang.org/grpc@v1.53.0/server.go:963 +0x24c
exit status 2
make: *** [run] Error 1