Skip to content

Commit 76cfd40

Browse files
committed
routerrpc: recover from panics during PoC
1 parent b8489a1 commit 76cfd40

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

lnrpc/routerrpc/imputed_cost.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ func parseImputedCostRestr(restr *lnrpc.ImputedCostRestriction) (
4141
func (s *Server) XImportImputedCosts(_ context.Context,
4242
req *ImportImputedCostsRequest) (*ImportImputedCostsResponse, error) {
4343

44+
// Recover from any panics during PoC of imputed cost.
45+
defer func() {
46+
if r := recover(); r != nil {
47+
log.Errorf("panic while XImportImputedCosts: %v", r)
48+
}
49+
}()
50+
4451
data := make(map[string]*ImputedCostNamespace)
4552
names := make(fn.Set[string])
4653

@@ -155,6 +162,13 @@ func unmarshalImputedParams(
155162
func (s *Server) XQueryImputedCosts(_ context.Context,
156163
req *QueryImputedCostsRequest) (*QueryImputedCostsResponse, error) {
157164

165+
// Recover from any panics during PoC of imputed cost.
166+
defer func() {
167+
if r := recover(); r != nil {
168+
log.Errorf("panic while XQueryImputedCosts: %v", r)
169+
}
170+
}()
171+
158172
names := fn.NewSet(req.Namespaces...)
159173
res := make([]*ImputedCostNamespace, 0, names.Size())
160174

@@ -207,6 +221,13 @@ func marshalImputedParams(
207221
func (s *Server) XDeleteImputedCosts(_ context.Context,
208222
req *DeleteImputedCostsRequest) (*DeleteImputedCostsResponse, error) {
209223

224+
// Recover from any panics during PoC of imputed cost.
225+
defer func() {
226+
if r := recover(); r != nil {
227+
log.Errorf("panic while XDeleteImputedCosts: %v", r)
228+
}
229+
}()
230+
210231
if len(req.Namespaces) == 0 {
211232
return nil, errors.New("at least one namespace required")
212233
}

lnrpc/routerrpc/router_backend.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ type MissionControl interface {
169169
func (r *RouterBackend) QueryRoutes(ctx context.Context,
170170
in *lnrpc.QueryRoutesRequest) (*lnrpc.QueryRoutesResponse, error) {
171171

172+
// Recover from any panics during PoC of imputed cost.
173+
defer func() {
174+
if r := recover(); r != nil {
175+
log.Errorf("panic while QueryRoutes: %v", r)
176+
}
177+
}()
178+
172179
routeReq, err := r.parseQueryRoutesRequest(in)
173180
if err != nil {
174181
return nil, err

lnrpc/routerrpc/router_server.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@ func (r *ServerShell) CreateSubServer(configRegistry lnrpc.SubServerConfigDispat
365365
func (s *Server) SendPaymentV2(req *SendPaymentRequest,
366366
stream Router_SendPaymentV2Server) error {
367367

368+
// Recover from any panics during PoC of imputed cost.
369+
defer func() {
370+
if r := recover(); r != nil {
371+
log.Errorf("panic while SendPaymentV2: %v", r)
372+
}
373+
}()
368374
// Set payment request attempt timeout.
369375
if req.TimeoutSeconds == 0 {
370376
req.TimeoutSeconds = DefaultPaymentTimeout

0 commit comments

Comments
 (0)