@@ -329,12 +329,11 @@ func (s *Server) invalidBlockChecker(ctx context.Context) {
329
329
}
330
330
331
331
// handleRequest is called as a go routine to handle a long-lived command.
332
- func (s * Server ) handleRequest (parentCtx context.Context , bws * bfgWs , wsid string , cmd protocol.Command , handler func (ctx context.Context ) (any , error )) {
332
+ func (s * Server ) handleRequest (pctx context.Context , bws * bfgWs , wsid string , cmd protocol.Command , handler func (ctx context.Context ) (any , error )) {
333
333
log .Tracef ("handleRequest: %v" , bws .addr )
334
334
defer log .Tracef ("handleRequest exit: %v" , bws .addr )
335
335
336
- ctx , cancel := context .WithTimeout (bws .requestContext ,
337
- time .Duration (s .cfg .RequestTimeout )* time .Second )
336
+ ctx , cancel := context .WithTimeout (pctx , time .Duration (s .cfg .RequestTimeout )* time .Second )
338
337
defer cancel ()
339
338
340
339
select {
@@ -393,8 +392,8 @@ func (s *Server) handleBitcoinBalance(ctx context.Context, bbr *bfgapi.BitcoinBa
393
392
}, nil
394
393
}
395
394
396
- func (s * Server ) handleOneBroadcastRequest (ctx context.Context , highPriority bool ) {
397
- ctx , cancel := context .WithTimeout (ctx , 5 * time .Second )
395
+ func (s * Server ) handleOneBroadcastRequest (pctx context.Context , highPriority bool ) {
396
+ ctx , cancel := context .WithTimeout (pctx , 5 * time .Second )
398
397
defer cancel ()
399
398
400
399
serializedTx , err := s .db .BtcTransactionBroadcastRequestGetNext (ctx , highPriority )
@@ -803,8 +802,8 @@ type bfgWs struct {
803
802
addr string
804
803
conn * protocol.WSConn
805
804
sessionId string
806
- listenerName string // "public" or "private"
807
- requestContext context.Context
805
+ listenerName string // "public" or "private"
806
+ requestContext context.Context // XXX get rid of this
808
807
notify map [notificationId ]struct {}
809
808
publicKey []byte
810
809
}
@@ -1086,8 +1085,7 @@ func (s *Server) handleWebsocketPublic(w http.ResponseWriter, r *http.Request) {
1086
1085
}
1087
1086
1088
1087
// Must complete handshake in WSHandshakeTimeout.
1089
- hsCtx , hsCancel := context .WithTimeout (context .Background (),
1090
- protocol .WSHandshakeTimeout )
1088
+ hsCtx , hsCancel := context .WithTimeout (r .Context (), protocol .WSHandshakeTimeout )
1091
1089
defer hsCancel ()
1092
1090
1093
1091
authenticator , err := auth .NewSecp256k1AuthServer ()
@@ -1421,16 +1419,16 @@ func hemiL2KeystonesToDb(l2ks []hemi.L2Keystone) []bfgd.L2Keystone {
1421
1419
return dbks
1422
1420
}
1423
1421
1424
- func (s * Server ) refreshCacheAndNotifiyL2Keystones () {
1425
- ctx , cancel := context .WithTimeout (context . Background () , 10 * time .Second )
1422
+ func (s * Server ) refreshCacheAndNotifiyL2Keystones (pctx context. Context ) {
1423
+ ctx , cancel := context .WithTimeout (pctx , 10 * time .Second )
1426
1424
defer cancel ()
1427
1425
1428
1426
s .refreshL2KeystoneCache (ctx )
1429
1427
go s .handleL2KeystonesNotification ()
1430
1428
}
1431
1429
1432
- func (s * Server ) saveL2Keystones (ctx context.Context , l2k []hemi.L2Keystone ) {
1433
- ctx , cancel := context .WithTimeout (ctx , 5 * time .Second )
1430
+ func (s * Server ) saveL2Keystones (pctx context.Context , l2k []hemi.L2Keystone ) {
1431
+ ctx , cancel := context .WithTimeout (pctx , 5 * time .Second )
1434
1432
defer cancel ()
1435
1433
1436
1434
ks := hemiL2KeystonesToDb (l2k )
@@ -1441,7 +1439,7 @@ func (s *Server) saveL2Keystones(ctx context.Context, l2k []hemi.L2Keystone) {
1441
1439
return
1442
1440
}
1443
1441
1444
- go s .refreshCacheAndNotifiyL2Keystones ()
1442
+ go s .refreshCacheAndNotifiyL2Keystones (pctx )
1445
1443
}
1446
1444
1447
1445
func (s * Server ) handleNewL2Keystones (ctx context.Context , nlkr * bfgapi.NewL2KeystonesRequest ) (any , error ) {
@@ -1482,9 +1480,7 @@ func handle(service string, mux *http.ServeMux, pattern string, handler func(htt
1482
1480
log .Infof ("handle (%v): %v" , service , pattern )
1483
1481
}
1484
1482
1485
- func (s * Server ) handleStateUpdates (table string , action string , payload , payloadOld interface {}) {
1486
- ctx := context .Background ()
1487
-
1483
+ func (s * Server ) handleStateUpdates (ctx context.Context , table string , action string , payload , payloadOld interface {}) {
1488
1484
// get the last known canonical chain height
1489
1485
s .mtx .RLock ()
1490
1486
heightBefore := s .canonicalChainHeight
@@ -1509,7 +1505,7 @@ func (s *Server) handleStateUpdates(table string, action string, payload, payloa
1509
1505
s .mtx .Unlock ()
1510
1506
}
1511
1507
1512
- func (s * Server ) handleAccessPublicKeys (table string , action string , payload , payloadOld interface {}) {
1508
+ func (s * Server ) handleAccessPublicKeys (ctx context. Context , table string , action string , payload , payloadOld interface {}) {
1513
1509
log .Tracef ("received payloads: %v, %v" , payload , payloadOld )
1514
1510
1515
1511
if action != "DELETE" {
@@ -1543,8 +1539,8 @@ func (s *Server) handleAccessPublicKeys(table string, action string, payload, pa
1543
1539
s .mtx .Unlock ()
1544
1540
}
1545
1541
1546
- func (s * Server ) handleL2KeystonesChange (table string , action string , payload , payloadOld any ) {
1547
- go s .refreshCacheAndNotifiyL2Keystones ()
1542
+ func (s * Server ) handleL2KeystonesChange (ctx context. Context , table string , action string , payload , payloadOld any ) {
1543
+ go s .refreshCacheAndNotifiyL2Keystones (ctx )
1548
1544
}
1549
1545
1550
1546
func (s * Server ) fetchRemoteL2Keystones (pctx context.Context ) {
@@ -1592,7 +1588,7 @@ func (s *Server) handleBFGWebsocketReadUnauth(ctx context.Context, conn *protoco
1592
1588
}
1593
1589
}
1594
1590
1595
- func (s * Server ) callBFG (parrentCtx context.Context , msg any ) (any , error ) {
1591
+ func (s * Server ) callBFG (pctx context.Context , msg any ) (any , error ) {
1596
1592
log .Tracef ("callBFG %T" , msg )
1597
1593
defer log .Tracef ("callBFG exit %T" , msg )
1598
1594
@@ -1601,7 +1597,7 @@ func (s *Server) callBFG(parrentCtx context.Context, msg any) (any, error) {
1601
1597
ch : make (chan any ),
1602
1598
}
1603
1599
1604
- ctx , cancel := context .WithTimeout (parrentCtx , s .bfgCallTimeout )
1600
+ ctx , cancel := context .WithTimeout (pctx , s .bfgCallTimeout )
1605
1601
defer cancel ()
1606
1602
1607
1603
// attempt to send
@@ -1629,11 +1625,11 @@ func (s *Server) callBFG(parrentCtx context.Context, msg any) (any, error) {
1629
1625
// Won't get here
1630
1626
}
1631
1627
1632
- func (s * Server ) handleBFGCallCompletion (parrentCtx context.Context , conn * protocol.Conn , bc bfgCmd ) {
1628
+ func (s * Server ) handleBFGCallCompletion (pctx context.Context , conn * protocol.Conn , bc bfgCmd ) {
1633
1629
log .Tracef ("handleBFGCallCompletion" )
1634
1630
defer log .Tracef ("handleBFGCallCompletion exit" )
1635
1631
1636
- ctx , cancel := context .WithTimeout (parrentCtx , s .bfgCallTimeout )
1632
+ ctx , cancel := context .WithTimeout (pctx , s .bfgCallTimeout )
1637
1633
defer cancel ()
1638
1634
1639
1635
log .Tracef ("handleBFGCallCompletion: %v" , spew .Sdump (bc .msg ))
0 commit comments