libp2p / libp2p/go-libp2p

use fx lifecycle hooks to start and stop services

Open
#1,876 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

effort/days exp/expert kind/enhancement
Dominant language
Go
Stars
6.9k
Forks
1.3k
Avg merge
13d 21h
Merged PRs (30d)
1

Description

Starting and stopping services on the host has long been a pain point. By using [fx's lifecycle hooks](https://uber-go.github.io/fx/lifecycle.html#lifecycle-hooks) we could potentially dramatically simplify our code base.

This is the `Close` logic in the `BasicHost`: https://github.com/libp2p/go-libp2p/blob/c48e78f0733d8bdb45ab766352e490b903983977/p2p/host/basic/basic_host.go#L972-L1011

There also exist wrapped hosts _only_ for hooking into the `Close` method, for example here: https://github.com/libp2p/go-libp2p/blob/c48e78f0733d8bdb45ab766352e490b903983977/p2p/host/autorelay/host.go#L7-L15

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Close logic in p2p/host/basic/basic_host.go and the wrapper in p2p/host/autorelay/host.go, then read the linked fx lifecycle hooks documentation. Trace how these hosts currently start and stop services and identify the lifecycle paths that need consolidation. Done means the service lifecycle uses fx hooks while preserving the existing start and stop behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
networking
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.