fix a race and optimize hello messages
LifecycleCtx can _only_ be called during startup as it appends an fx hook. Worse, this was causing us to append an fx hook on every single hello message, leaking memory (and probably causing other shutdown issues...).
This commit is contained in:
parent
7245ac2b69
commit
c463582528
@ -42,11 +42,13 @@ func RunHello(mctx helpers.MetricsCtx, lc fx.Lifecycle, h host.Host, svc *hello.
|
||||
return xerrors.Errorf("failed to subscribe to event bus: %w", err)
|
||||
}
|
||||
|
||||
ctx := helpers.LifecycleCtx(mctx, lc)
|
||||
|
||||
go func() {
|
||||
for evt := range sub.Out() {
|
||||
pic := evt.(event.EvtPeerIdentificationCompleted)
|
||||
go func() {
|
||||
if err := svc.SayHello(helpers.LifecycleCtx(mctx, lc), pic.Peer); err != nil {
|
||||
if err := svc.SayHello(ctx, pic.Peer); err != nil {
|
||||
protos, _ := h.Peerstore().GetProtocols(pic.Peer)
|
||||
agent, _ := h.Peerstore().Get(pic.Peer, "AgentVersion")
|
||||
if protosContains(protos, hello.ProtocolID) {
|
||||
|
Loading…
Reference in New Issue
Block a user