Skip to content

Commit

Permalink
fix: allow daemon to start correctly if the API is null
Browse files Browse the repository at this point in the history
Fixes: #10056
  • Loading branch information
Jorropo committed Aug 11, 2023
1 parent b8c4725 commit a3c72d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,11 @@ func serveHTTPApi(req *cmds.Request, cctx *oldcmds.Context) (<-chan error, error
return nil, fmt.Errorf("serveHTTPApi: ConstructNode() failed: %s", err)
}

if err := node.Repo.SetAPIAddr(rewriteMaddrToUseLocalhostIfItsAny(listeners[0].Multiaddr())); err != nil {
return nil, fmt.Errorf("serveHTTPApi: SetAPIAddr() failed: %w", err)
if len(listeners) > 0 {
// Only add an api file if the API is running.

Check warning on line 718 in cmd/ipfs/daemon.go

View check run for this annotation

Codecov / codecov/patch

cmd/ipfs/daemon.go#L717-L718

Added lines #L717 - L718 were not covered by tests
if err := node.Repo.SetAPIAddr(rewriteMaddrToUseLocalhostIfItsAny(listeners[0].Multiaddr())); err != nil {
return nil, fmt.Errorf("serveHTTPApi: SetAPIAddr() failed: %w", err)
}

Check warning on line 721 in cmd/ipfs/daemon.go

View check run for this annotation

Codecov / codecov/patch

cmd/ipfs/daemon.go#L720-L721

Added lines #L720 - L721 were not covered by tests
}

errc := make(chan error)
Expand Down
18 changes: 18 additions & 0 deletions test/cli/daemon_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cli

import (
"testing"

"github.com/ipfs/kubo/test/cli/harness"
)

func TestDaemon(t *testing.T) {
t.Parallel()

t.Run("daemon starts if api is set to null", func(t *testing.T) {
t.Parallel()
node := harness.NewT(t).NewNode().Init()
node.SetIPFSConfig("API", nil)
node.IPFS("daemon") // can't use .StartDaemon because it do a .WaitOnAPI
})
}

0 comments on commit a3c72d6

Please sign in to comment.