Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kubo, invalid memory address or nil pointer dereference from IpfsNode.Bootstrap #9876

Closed
3 tasks done
AxelGard opened this issue May 12, 2023 · 2 comments
Closed
3 tasks done
Assignees
Labels
kind/bug A bug in existing code (including security flaws) need/analysis Needs further analysis before proceeding need/triage Needs initial labeling and prioritization

Comments

@AxelGard
Copy link

Checklist

Installation method

ipfs-desktop

Version

v.0.20.0

Config

No response

Description

I posted on the forums and stack overflow about this issue because I assumed this was my fault for doing something wrong.
However, it appears as if it is not obvious what I'm doing wrong or there is a bug.
If it is not a bug then this needs to be expressed how to do in the documentation since this is basic stuff.
Hence, why I'm posting this as an issue.

I’m getting an invalid memory address or nil pointer dereference from IpfsNode.Bootstrap I assume that there is some panic in bootstrap Round, but am I doing something wrong here? Or is there a bug? I’m using kubo v0.20.0 here is my code:

package main

import (
    "context"
    "fmt"

    "github.com/ipfs/kubo/config"
    "github.com/ipfs/kubo/core"
    "github.com/ipfs/kubo/core/bootstrap"
)

func main() {
    ctx := context.Background()
    conf := core.BuildCfg{}
    node, err := core.NewNode(ctx, &conf)
    if err != nil {
        panic(err)
    }
    peers, err := config.DefaultBootstrapPeers()
    if err != nil {
        panic(err)
    }
    bs_conf := bootstrap.BootstrapConfigWithPeers(peers)
    err = node.Bootstrap(bs_conf) // this gets nil pointer dereference
    fmt.Println("THIS LINE WILL NOT PRINT")
    if err != nil {
        panic(err)
    }
}

The full error is:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0xee49eb]

goroutine 69 [running]:
github.com/ipfs/kubo/core/bootstrap.bootstrapRound({0x18bf1d8?, 0xc0000b05f0?}, {0x0, 0x0}, {0x0?, 0x0?, 0x0?, 0xc0006240c0?})
        /home/axel/go/pkg/mod/github.com/ipfs/kubo@v0.20.0/core/bootstrap/bootstrap.go:118 +0xab
github.com/ipfs/kubo/core/bootstrap.Bootstrap.func1({0x18cbd58?, 0xc0006226c0?})
        /home/axel/go/pkg/mod/github.com/ipfs/kubo@v0.20.0/core/bootstrap/bootstrap.go:89 +0xdc
github.com/jbenet/goprocess.(*process).Go.func1()
        /home/axel/go/pkg/mod/github.com/jbenet/goprocess@v0.1.4/impl-mutex.go:134 +0x36
created by github.com/jbenet/goprocess.(*process).Go
        /home/axel/go/pkg/mod/github.com/jbenet/goprocess@v0.1.4/impl-mutex.go:133 +0x238
exit status 2

the bs_conf := bootstrap.BootstrapConfigWithPeers(peers) is {4 30s 10s 0x112b700}

@AxelGard AxelGard added kind/bug A bug in existing code (including security flaws) need/triage Needs initial labeling and prioritization labels May 12, 2023
@AxelGard AxelGard moved this to In Progress in @AxelGard's seekIPNS kanban May 12, 2023
@lidel lidel added the need/analysis Needs further analysis before proceeding label May 15, 2023
@lidel lidel moved this to 🥞 Todo in IPFS Shipyard Team May 15, 2023
@aschmahmann
Copy link
Contributor

aschmahmann commented May 15, 2023

Closing as this seems like a forums/question issue and how to resolve the issue was described at https://discuss.ipfs.tech/t/kubo-invalid-memory-address-or-nil-pointer-dereference-from-ipfsnode-bootstrap/16417/7. If there's more discussion to be had about a bug to be addressed here the issue can be modified to describe the bug and reopened.

@github-project-automation github-project-automation bot moved this from In Progress to Done in @AxelGard's seekIPNS kanban May 15, 2023
@github-project-automation github-project-automation bot moved this from 🥞 Todo to 🎉 Done in IPFS Shipyard Team May 15, 2023
@AxelGard
Copy link
Author

AxelGard commented May 15, 2023

Thanks @aschmahmann, I will post your answer here as well. if the forum page is ever lost:

Your issue seems to be that you use conf := core.BuildCfg{} which will set BulidCfg.Offline to false which means that you will not have a libp2p node instantiated with which to bootstrap which then gives you a null reference exception since you’re trying to bootstrap using a non-existent libp2p networking host.

If you set Offline to true it won’t panic anymore since the host will start.

That being said I’m not sure exactly what you’re trying to do and maybe using kubo as a library does enough of the job for you. However, you might be better suited to using something like GitHub - ipfs/boxo: A reference library for building IPFS applications and implementations. if you’re planning on building a custom IPFS application in Go.

There’s a relatively recent doc describing some of the tradeoffs a developer might make in deciding how to move from Kubo to something similar, but more configurable in kubo/customizing.md at master · ipfs/kubo · GitHub.

by @aschmahmann

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws) need/analysis Needs further analysis before proceeding need/triage Needs initial labeling and prioritization
Projects
No open projects
Archived in project
Development

No branches or pull requests

3 participants