NebulousLabs / Sia

Blockchain-based marketplace for file storage. Project has moved to GitLab: https://gitlab.com/NebulousLabs/Sia
https://sia.tech
MIT License
2.71k stars 440 forks source link

invalid memory address or nil pointer dereference #3034

Closed falconwoods closed 6 years ago

falconwoods commented 6 years ago

BUG REPORT

Stack Trace or error message sudo siad -M gctwh Sia Daemon v1.3.3 WARN: compiled without build commit or version. To compile correctly, please use the makefile Loading... (0/5) Loading siad... (1/5) Loading gateway... (2/5) Loading consensus... (3/5) Loading transaction pool... (4/5) Loading wallet... (5/5) Loading host... Finished loading in 1.335164035 seconds panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x4 pc=0x123bc]

goroutine 528 [running]: sync/atomic.addUint64(0x11c6644c, 0x100000, 0x0, 0x7, 0x8) /home/pi/openSource/go-go1.10.2/src/sync/atomic/64bit_arm.go:31 +0x4c github.com/NebulousLabs/Sia/sync.(TryRWMutex).Lock(0x11c6644c) /home/pi/go/src/github.com/NebulousLabs/Sia/sync/tryrwmutex.go:29 +0x30 github.com/NebulousLabs/Sia/modules/host/contractmanager.(writeAheadLog).managedAddStorageFolder(0x11567ba8, 0x11c663f0, 0x0, 0x0) /home/pi/go/src/github.com/NebulousLabs/Sia/modules/host/contractmanager/storagefolderadd.go:97 +0x38 github.com/NebulousLabs/Sia/modules/host/contractmanager.(ContractManager).AddStorageFolder(0x11567b20, 0x119261e0, 0x18, 0xd0000000, 0x45, 0x0, 0x0) /home/pi/go/src/github.com/NebulousLabs/Sia/modules/host/contractmanager/storagefolderadd.go:370 +0x260 github.com/NebulousLabs/Sia/node/api.(API).storageFoldersAddHandler(0x115ac0a0, 0x641fc8, 0x11c662d0, 0x11d80000, 0x0, 0x0, 0x0) /home/pi/go/src/github.com/NebulousLabs/Sia/node/api/host.go:315 +0xfc github.com/NebulousLabs/Sia/node/api.(API).(github.com/NebulousLabs/Sia/node/api.storageFoldersAddHandler)-fm(0x641fc8, 0x11c662d0, 0x11d80000, 0x0, 0x0, 0x0) /home/pi/go/src/github.com/NebulousLabs/Sia/node/api/routes.go:53 +0x4c github.com/julienschmidt/httprouter.(Router).ServeHTTP(0x117ce800, 0x641fc8, 0x11c662d0, 0x11d80000) /home/pi/go/src/github.com/julienschmidt/httprouter/router.go:334 +0x658 github.com/NebulousLabs/Sia/node/api.RequireUserAgent.func1(0x641fc8, 0x11c662d0, 0x11d80000) /home/pi/go/src/github.com/NebulousLabs/Sia/node/api/routes.go:177 +0x98 net/http.HandlerFunc.ServeHTTP(0x117ce8c0, 0x641fc8, 0x11c662d0, 0x11d80000) /home/pi/openSource/go-go1.10.2/src/net/http/server.go:1947 +0x34 github.com/NebulousLabs/Sia/node/api.cleanCloseHandler.func1.1(0x11c500c0, 0x640190, 0x117ce8c0, 0x641fc8, 0x11c662d0, 0x11d80000) /home/pi/go/src/github.com/NebulousLabs/Sia/node/api/routes.go:148 +0x60 created by github.com/NebulousLabs/Sia/node/api.cleanCloseHandler.func1 /home/pi/go/src/github.com/NebulousLabs/Sia/node/api/routes.go:146 +0x78

Expected Behavior

How to reproduce it (as minimally and precisely as possible)

  1. build sia 1.3.3 on raspberry 3B
  2. run daemon execute "sudo siad -M gctwh"
  3. init wallet, unlock wallet, create wallet address
  4. add folder execute "siac host folder add /mnt/wd-p2/sia-data-300G/ 300GB" then siad crashed.

Environment

DavidVorick commented 6 years ago

In the future can you build with make? If you do, the startup message for siad will include the commit number, so that we can more easily track down the issue.

This is probably enough for us to trace though.

falconwoods commented 6 years ago

Here is the output with Git Revision:

Running with debugging enabled Sia Daemon v1.3.3 Git Revision 156bf265

falconwoods commented 6 years ago

Here is the complete output:

./siad -M gctwh
Running with debugging enabled
Sia Daemon v1.3.3
Git Revision 156bf265
Loading...
(0/5) Loading siad...
(1/5) Loading gateway...
(2/5) Loading consensus...
(3/5) Loading transaction pool...
(4/5) Loading wallet...
(5/5) Loading host...
Finished loading in 0.258022928 seconds
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x4 pc=0x11f6c]

goroutine 683 [running]:
sync/atomic.addUint64(0x1205429c, 0x100000, 0x0, 0x7, 0x8)
        /home/pi/openSource/go-go1.10.2/src/sync/atomic/64bit_arm.go:31 +0x4c
github.com/NebulousLabs/Sia/sync.(*TryRWMutex).Lock(0x1205429c)
        /home/pi/go/src/github.com/NebulousLabs/Sia/sync/tryrwmutex.go:29 +0x30
github.com/NebulousLabs/Sia/modules/host/contractmanager.(*writeAheadLog).managedAddStorageFolder(0x122f0e88, 0x12054240, 0x0, 0x0)
        /home/pi/go/src/github.com/NebulousLabs/Sia/modules/host/contractmanager/storagefolderadd.go:97 +0x38
github.com/NebulousLabs/Sia/modules/host/contractmanager.(*ContractManager).AddStorageFolder(0x122f0e00, 0x120443a0, 0x18, 0xd0000000, 0x45, 0x0, 0x0)
        /home/pi/go/src/github.com/NebulousLabs/Sia/modules/host/contractmanager/storagefolderadd.go:370 +0x260
github.com/NebulousLabs/Sia/node/api.(*API).storageFoldersAddHandler(0x123070e0, 0x66a660, 0x12054120, 0x11f9e200, 0x0, 0x0, 0x0)
        /home/pi/go/src/github.com/NebulousLabs/Sia/node/api/host.go:315 +0xfc
github.com/NebulousLabs/Sia/node/api.(*API).(github.com/NebulousLabs/Sia/node/api.storageFoldersAddHandler)-fm(0x66a660, 0x12054120, 0x11f9e200, 0x0, 0x0, 0x
0)
        /home/pi/go/src/github.com/NebulousLabs/Sia/node/api/routes.go:53 +0x4c
github.com/julienschmidt/httprouter.(*Router).ServeHTTP(0x12448e20, 0x66a660, 0x12054120, 0x11f9e200)
        /home/pi/go/src/github.com/julienschmidt/httprouter/router.go:334 +0x658
github.com/NebulousLabs/Sia/node/api.RequireUserAgent.func1(0x66a660, 0x12054120, 0x11f9e200)
        /home/pi/go/src/github.com/NebulousLabs/Sia/node/api/routes.go:177 +0x98
net/http.HandlerFunc.ServeHTTP(0x12448ee0, 0x66a660, 0x12054120, 0x11f9e200)
        /home/pi/openSource/go-go1.10.2/src/net/http/server.go:1947 +0x34
github.com/NebulousLabs/Sia/node/api.cleanCloseHandler.func1.1(0x123a22c0, 0x668818, 0x12448ee0, 0x66a660, 0x12054120, 0x11f9e200)
        /home/pi/go/src/github.com/NebulousLabs/Sia/node/api/routes.go:148 +0x60
created by github.com/NebulousLabs/Sia/node/api.cleanCloseHandler.func1
        /home/pi/go/src/github.com/NebulousLabs/Sia/node/api/routes.go:146 +0x78
falconwoods commented 6 years ago

I really want to run sia on my raspberry with raspberry os. I know about that there is a special image for pi which based on geento to run sia. I haven't tried that image yet but I prefer raspberry os.

It will be fantastic if we can success running sia on raspberry pi! There will be more fellows join sia.

lukechampine commented 6 years ago

@wxlcat I suspect that this is due to a 64-bit field not being properly aligned on ARM. Can you apply the following patch and try again?

diff --git a/modules/host/contractmanager/storagefolder.go b/modules/host/contractmanager/storagefolder.go
index 7208fc5..131099f 100644
--- a/modules/host/contractmanager/storagefolder.go
+++ b/modules/host/contractmanager/storagefolder.go
@@ -82,6 +82,11 @@ var (
 // sectors are being stored in the folder. What sectors are being stored is
 // managed by the contract manager's sectorLocations map.
 type storageFolder struct {
+       // mu needs to be RLocked to safetly write new sectors into the storage
+       // folder. mu needs to be Locked when the folder is being added, removed,
+       // or resized.
+       mu sync.TryRWMutex
+
        // Progress statistics that can be reported to the user. Typically for long
        // running actions like adding or resizing a storage folder.
        atomicProgressNumerator   uint64
@@ -113,11 +118,6 @@ type storageFolder struct {
        availableSectors map[sectorID]uint32
        sectors          uint64

-       // mu needs to be RLocked to safetly write new sectors into the storage
-       // folder. mu needs to be Locked when the folder is being added, removed,
-       // or resized.
-       mu sync.TryRWMutex
-
        // An open file handle is kept so that writes can easily be made to the
        // storage folder without needing to grab a new file handle. This also
        // makes it easy to do delayed-syncing.
falconwoods commented 6 years ago

It works,Thanks a lot! Will this issue be fixed in the next version?

lukechampine commented 6 years ago

Yes, we can include this in the next release. Just need to PR the patch above.