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

Relations of has many causes panic in armv7 device #52

Closed
levin-go opened this issue Aug 27, 2024 · 15 comments
Closed

Relations of has many causes panic in armv7 device #52

levin-go opened this issue Aug 27, 2024 · 15 comments
Labels
bug Something isn't working

Comments

@levin-go
Copy link

levin-go commented Aug 27, 2024

The same code can run normally on my computer (x86 windows) and device (armv7 Linux) without using a one to many relationship. Once a one to many relationship is used, it can run normally on my computer (x86 Windows). But when my device (armv7 Linux ) is running, it will cause a panic.

Basic info

  • Objectbox version: objectbox-go v1.8.0
  • Objectbox lib version: libobjectbox.so v4.0.1
  • Device: x86 Windows and armv7 Linux
  • Reproducibility: always

Code

  • main.go
package main

import (
	"fmt"
	"github.com/objectbox/objectbox-go/objectbox"
	"objectboxTest/objectboxlib/model"
)

func initObjectBox() *objectbox.ObjectBox {
	objectBox, err := objectbox.NewBuilder().Model(model.ObjectBoxModel()).Directory("./opt").Build()
	if err != nil {
		fmt.Println(err)
		return nil
	}
	return objectBox
}

func main() {
	// load objectbox
	ob := initObjectBox()
	defer ob.Close() // In a server app, you would just keep ob and close on shutdown
	box := model.BoxForTask(ob)
	box2 := model.BoxForWorkers(ob)
	if box == nil || box2 == nil {
		panic("box ini fail")
	}
	worker1 := model.Workers{Name: "Petter", Age: 18}
	worker2 := model.Workers{Name: "Leven", Age: 28}
	workers := []*model.Workers{&worker1, &worker2}
	id, _ := box.Put(&model.Task{
		Text:    "Buy milk",
		Workers: workers,
	})
	tasks, err := box.Get(id) // Read
	if err != nil {
		fmt.Println("read err ", err)
		return
	}
	fmt.Println(tasks)
}

  • model/task.go
package model

//go:generate go run github.com/objectbox/objectbox-go/cmd/objectbox-gogen

// Put this on a new line to enable sync: // `objectbox:"sync"`
type Task struct {
	Id           uint64
	Text         string
	Name         string
	DataType     string
	Value        float64
	ValueStr     string
	DateCreated  int64
	DateFinished int64
	Workers      []*Workers
}

type Workers struct {
	Id   uint64
	Name string
	Age  int
}

Windows Log

&{6 Buy milk 0 0 0 [0xc000086020 0xc000086040]}

Linux (ARMV7) Log

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

goroutine 1 [running, locked to thread]:
github.com/objectbox/objectbox-go/objectbox.dataVisitorDispatch(0xb55f17b0, 0x40, 0x4137c0)
	/home/lich/go/pkg/mod/github.com/levin-go/[email protected]/objectbox/datavisitorc.go:43 +0x50
github.com/objectbox/objectbox-go/objectbox._Cfunc_obx_box_visit_many(0x2cdff0, 0x2ce078, 0x142d4c, 0x4137c0)
	_cgo_gotypes.go:745 +0x38
github.com/objectbox/objectbox-go/objectbox.(*Box).GetManyExisting.func2.1(0x5147b0, 0x5147e0, 0x4137c0)
	/home/lich/go/pkg/mod/github.com/levin-go/[email protected]/objectbox/box.go:531 +0xc8
github.com/objectbox/objectbox-go/objectbox.(*Box).GetManyExisting.func2(0x4137c0)
	/home/lich/go/pkg/mod/github.com/levin-go/[email protected]/objectbox/box.go:531 +0x70
github.com/objectbox/objectbox-go/objectbox.(*Box).readUsingVisitor.func2.1()
	/home/lich/go/pkg/mod/github.com/levin-go/[email protected]/objectbox/box.go:621 +0x24
github.com/objectbox/objectbox-go/objectbox.cCall(0x4d7cf4)
	/home/lich/go/pkg/mod/github.com/levin-go/[email protected]/objectbox/c-tools.go:34 +0x20
github.com/objectbox/objectbox-go/objectbox.(*Box).readUsingVisitor.func2()
	/home/lich/go/pkg/mod/github.com/levin-go/[email protected]/objectbox/box.go:621 +0x4c
github.com/objectbox/objectbox-go/objectbox.(*ObjectBox).runInTxn(0x505860, 0x1, 0x4d7d64)
	/home/lich/go/pkg/mod/github.com/levin-go/[email protected]/objectbox/objectbox.go:155 +0xcc
github.com/objectbox/objectbox-go/objectbox.(*ObjectBox).RunInReadTx(...)
	/home/lich/go/pkg/mod/github.com/levin-go/[email protected]/objectbox/objectbox.go:110
github.com/objectbox/objectbox-go/objectbox.(*Box).readUsingVisitor(0x5147b0, 0x1, 0x4d7da0)
	/home/lich/go/pkg/mod/github.com/levin-go/[email protected]/objectbox/box.go:620 +0x27c
github.com/objectbox/objectbox-go/objectbox.(*Box).GetManyExisting(0x5147b0, {0x4137b0, 0x2, 0x2})
	/home/lich/go/pkg/mod/github.com/levin-go/[email protected]/objectbox/box.go:533 +0x158
objectboxTest/objectboxlib/model.(*WorkersBox).GetManyExisting(...)
	/mnt/d/gitlab/tools/objectboxTest/objectboxlib/model/task.obx.go:617
objectboxTest/objectboxlib/model.task_EntityInfo.Load({{0x1}, 0x284bb4920ec6bdbe}, 0x505860, {0xb55f1680, 0x80, 0x80})
	/mnt/d/gitlab/tools/objectboxTest/objectboxlib/model/task.obx.go:170 +0x144
github.com/objectbox/objectbox-go/objectbox.(*Box).Get.func1()
	/home/lich/go/pkg/mod/github.com/levin-go/[email protected]/objectbox/box.go:479 +0x18c
github.com/objectbox/objectbox-go/objectbox.(*ObjectBox).runInTxn(0x505860, 0x1, 0x4d7f10)
	/home/lich/go/pkg/mod/github.com/levin-go/[email protected]/objectbox/objectbox.go:155 +0xcc
github.com/objectbox/objectbox-go/objectbox.(*ObjectBox).RunInReadTx(...)
	/home/lich/go/pkg/mod/github.com/levin-go/[email protected]/objectbox/objectbox.go:110
github.com/objectbox/objectbox-go/objectbox.(*Box).Get(0x514790, 0x3)
	/home/lich/go/pkg/mod/github.com/levin-go/[email protected]/objectbox/box.go:470 +0x80
objectboxTest/objectboxlib/model.(*TaskBox).Get(0x4d7f90, 0x3)
	/mnt/d/gitlab/tools/objectboxTest/objectboxlib/model/task.obx.go:258 +0x30
main.main()
	/mnt/d/gitlab/tools/objectboxTest/main.go:34 +0x198
@levin-go levin-go added the bug Something isn't working label Aug 27, 2024
@levin-go
Copy link
Author

I have identified the triggering cause.

objectbox/[email protected]/objectbox/objectbox.go : 91

var supportsResultArray = bool(C.obx_has_feature(C.OBXFeature_ResultArray))

x86 windows the supportsResultArray == true, but armv7 linux the supportsResultArray == false

so, in the method of func (box *Box) GetManyExisting(ids ...uint64) (slice interface{}, err error) will perform different processing.

But I am not sure about the meaning of bool(C.obx_has_feature(C.OBXFeature_ResultArray)) .

@greenrobot
Copy link
Member

Thanks for reporting and investigating. First, this is a legit check:

var supportsResultArray = bool(C.obx_has_feature(C.OBXFeature_ResultArray))

For 32 bit, it has to function differently as the underlying mmap works "simpler" on 64-bit.

@levin-go
Copy link
Author

I am now forcing the supportsRultArray to be set to true. My device (armv7 linux) is working now. I hope this issue can be resolved as soon as possible.
Thank you!

@greenrobot
Copy link
Member

I am now forcing the supportsRultArray to be set to true.

This is risky. It may seem fine for a while but yield garbage data at any point.

@levin-go
Copy link
Author

Thank you for your reply again.
Do you have any good idea for solving this problem? Or do you have time to test and address this issue recently? I can cooperate with the testing.

@greenrobot
Copy link
Member

Can you provide some info on your setup (e.g. hardware, OS, or whatever could be special on your side)?
Armv7 is tested as part of our CI, so we're trying to find out what's different...

@levin-go
Copy link
Author

Hardware

OS

Openwrt 18.06
Source

@greenrobot
Copy link
Member

Thanks for the info. Please have some patience...

One thing that could be helpful would be to add armv7 to GitHub actions (e.g. via https://github.com/marketplace/actions/run-on-architecture). A pull requests would be welcome.

@github-staff github-staff deleted a comment from levin-go Aug 27, 2024
@levin-go
Copy link
Author

Thank you!
looking forward to the problem being resolved!

I am not familiar with GitHub actions at all. If it is necessary, please let me know and I will study how to use it.

@greenrobot
Copy link
Member

greenrobot commented Aug 28, 2024

Update from our side: we can now reproduce a similar issue, so we have something to look into. We'll keep you updated...

@levin-go
Copy link
Author

Thank you!

@greenrobot
Copy link
Member

Fixed internally, will be part of the next release (we do not have a date yet).

@levin-go
Copy link
Author

I am in a hurry to test and hope to update the version as soon as possible. Thank you!

@greenrobot
Copy link
Member

Here you go: https://github.com/objectbox/objectbox-go/releases/tag/v1.8.1

Let us know if it works for you now.

@levin-go
Copy link
Author

Tested successfully!
Give a thumbs up for your efficiency!

@github-staff github-staff deleted a comment from mayank785 Oct 23, 2024
@github-staff github-staff deleted a comment from mayank785 Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants
@greenrobot @levin-go and others