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

Crash when removing relation and related entity #490

Closed
williamwue opened this issue Jul 2, 2018 · 18 comments
Closed

Crash when removing relation and related entity #490

williamwue opened this issue Jul 2, 2018 · 18 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@williamwue
Copy link

williamwue commented Jul 2, 2018

When I upgrade app it would crash when init objectbox, logcat is below:

    --------- beginning of crash
07-02 10:41:32.395 7478-7519/com.gnet.uc A/libc: Fatal signal 11 (SIGSEGV), code -6, fault addr 0x1d36 in tid 7519 (Thread-4)
07-02 10:41:32.397 404-404/? I/MIUINDBG_HOOK: hook hook_sigtimedwait
07-02 10:41:32.477 7524-7524/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
07-02 10:41:32.478 7524-7524/? A/DEBUG: Build fingerprint: 'Xiaomi/helium/helium:7.0/NRD90M/V9.5.2.0.NBDCNFA:user/release-keys'
    Revision: '0'
    ABI: 'arm'
    pid: 7478, tid: 7519, name: Thread-4  >>> com.gnet.uc <<<
    signal 11 (SIGSEGV), code -6 (SI_TKILL), fault addr 0x1d36
07-02 10:41:32.479 7524-7524/? A/DEBUG:     r0 00000000  r1 00000012  r2 e31ec381  r3 00000000
        r4 e12cdce0  r5 e12cdd54  r6 00009be7  r7 ccbcb1f0
        r8 00000000  r9 ccbcb3a4  sl 00000000  fp 00000000
        ip cca71e70  sp ccbcb168  lr cc997775  pc cc9c1c86  cpsr 600b0030
07-02 10:41:32.484 7524-7524/? A/DEBUG: backtrace:
        #00 pc 000b4c86  /data/app/com.gnet.uc-1/lib/arm/libobjectbox.so (_ZNK9objectbox6Schema20getEntityByIdOrThrowEj+21)
        #01 pc 0008a771  /data/app/com.gnet.uc-1/lib/arm/libobjectbox.so (_ZN9objectbox6Cursor22getForeignEntityCursorEj+80)
        #02 pc 0008ac1f  /data/app/com.gnet.uc-1/lib/arm/libobjectbox.so (_ZN9objectbox6Cursor16findBacklinkKeysEPNS_8PropertyEyRNSt6__ndk16vectorIyNS3_9allocatorIyEEEE+58)
        #03 pc 0008a69b  /data/app/com.gnet.uc-1/lib/arm/libobjectbox.so (_ZN9objectbox6Cursor14clearBacklinksEy+86)
07-02 10:41:32.485 7524-7524/? A/DEBUG:     #04 pc 0008a335  /data/app/com.gnet.uc-1/lib/arm/libobjectbox.so (_ZN9objectbox6Cursor6removeEv+336)
        #05 pc 0008c351  /data/app/com.gnet.uc-1/lib/arm/libobjectbox.so (_ZN9objectbox6Cursor9removeAllEv+86)
        #06 pc 000bb7ed  /data/app/com.gnet.uc-1/lib/arm/libobjectbox.so (_ZN9objectbox8SchemaDb23removeEntityWithAllDataEPKNS_6EntityE+36)
        #07 pc 000bfa09  /data/app/com.gnet.uc-1/lib/arm/libobjectbox.so (_ZN9objectbox10SchemaSync10syncSchemaERNS_13SchemaCatalogERNS_6SchemaES4_+520)
        #08 pc 000bc271  /data/app/com.gnet.uc-1/lib/arm/libobjectbox.so (_ZN9objectbox10SchemaSync4syncENSt6__ndk110shared_ptrINS_6SchemaEEEPKNS_5model5ModelE+248)
        #09 pc 000bbe7f  /data/app/com.gnet.uc-1/lib/arm/libobjectbox.so (_ZN9objectbox10SchemaSync4syncEPKNS_5model5ModelE+154)
        #10 pc 000cead3  /data/app/com.gnet.uc-1/lib/arm/libobjectbox.so (Java_io_objectbox_BoxStore_nativeCreate+170)
        #11 pc 02ddf20d  /data/app/com.gnet.uc-1/oat/arm/base.odex (offset 0x2d7c000)
@williamwue
Copy link
Author

And in BoxStore.java, it show me that:
/**
* Diagnostics: If this method crashes on a device, please send us the logcat output.
*/
static native long nativeCreate(String directory, long maxDbSizeInKByte, int maxReaders, byte[] model);

@greenrobot
Copy link
Member

Is this reproducible? Which version is it?

@Yazon2006
Copy link

Yazon2006 commented Jul 2, 2018

I got it recently. In my case problem was in attempt to deploy existing db image instead of empty after access to db.
So I suppose the crash is achievable in following steps:

  1. Access to db, e.g. boxstore.boxFor<Foo>()[0]
  2. Copy existing db image from assets to objectBox folder (data/data/com.app.package/files/objectbox/objectbox)
    Or create new one.
  3. Crash
    It looks like the problem is in concurrent work with filesystem.

@greenrobot
Copy link
Member

OK, we should look into it to fail more nicely...

@williamwue
Copy link
Author

williamwue commented Jul 3, 2018

@greenrobot Yes, it is reproducible. And objectbox version is v1.3.4.
More info:

  1. I have delete my default.json file by mistake at first.
  2. The objectbox rebuild default.json file, but its IDs also reset, so I follow steps (https://docs.objectbox.io/advanced/meta-model-ids-and-uids)to increase IDs and test it to upgrade my recent app, the result is OK.
  3. But some app users report that it would crash when upgrade app, the logcat show me that nativeCreate crash.

@greenrobot
Copy link
Member

greenrobot commented Jul 3, 2018

@williamwue So you can rule out it is the same scenario compared to Yazon2006's?

some app users report that it would crash when upgrade app

Do you have a percentage of users?

@s0nerik
Copy link

s0nerik commented Jul 6, 2018

I've got a crash and it's logcat output looks very similar to the one reported above:

07-05 17:52:08.826 18281-18281/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
07-05 17:52:08.827 18281-18281/? A/DEBUG: Build fingerprint: 'htc/m8_google/htc_m8:6.0/MRA58K.H6/648564:user/release-keys'
    Revision: '0'
    ABI: 'arm'
    pid: 18256, tid: 18256, name: .app.tech.stage  >>> com.myapp.app.tech.stage <<<
    signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x10
    Cause: null pointer dereference
        r0 00000000  r1 00000005  r2 3249cccc  r3 00000000
        r4 9bb324c0  r5 bed031c8  r6 9bb32534  r7 bed03170
        r8 00000000  r9 9bb324c0  sl bed031e8  fp 00000000
        ip 8a5b917c  sp bed03168  lr 8a4ae7d1  pc 8a4cfeb6  cpsr 600b0030
07-05 17:52:08.831 18281-18281/? A/DEBUG: backtrace:
07-05 17:52:08.832 18281-18281/? A/DEBUG:     #00 pc 0005feb6  /data/app/com.myapp.app.tech.stage-lyxDCugOEC6rwPVQExvu6A==/lib/arm/libobjectbox.so
        #01 pc 0003e7cd  /data/app/com.myapp.app.tech.stage-lyxDCugOEC6rwPVQExvu6A==/lib/arm/libobjectbox.so
        #02 pc 0003ebd3  /data/app/com.myapp.app.tech.stage-lyxDCugOEC6rwPVQExvu6A==/lib/arm/libobjectbox.so
        #03 pc 0003fb4f  /data/app/com.myapp.app.tech.stage-lyxDCugOEC6rwPVQExvu6A==/lib/arm/libobjectbox.so
        #04 pc 0003f939  /data/app/com.myapp.app.tech.stage-lyxDCugOEC6rwPVQExvu6A==/lib/arm/libobjectbox.so
        #05 pc 0003f801  /data/app/com.myapp.app.tech.stage-lyxDCugOEC6rwPVQExvu6A==/lib/arm/libobjectbox.so
        #06 pc 00063551  /data/app/com.myapp.app.tech.stage-lyxDCugOEC6rwPVQExvu6A==/lib/arm/libobjectbox.so
        #07 pc 00065d83  /data/app/com.myapp.app.tech.stage-lyxDCugOEC6rwPVQExvu6A==/lib/arm/libobjectbox.so
        #08 pc 00063e41  /data/app/com.myapp.app.tech.stage-lyxDCugOEC6rwPVQExvu6A==/lib/arm/libobjectbox.so
        #09 pc 00063c17  /data/app/com.myapp.app.tech.stage-lyxDCugOEC6rwPVQExvu6A==/lib/arm/libobjectbox.so
        #10 pc 000377ab  /data/app/com.myapp.app.tech.stage-lyxDCugOEC6rwPVQExvu6A==/lib/arm/libobjectbox.so
        #11 pc 0007355d  /data/app/com.myapp.app.tech.stage-lyxDCugOEC6rwPVQExvu6A==/lib/arm/libobjectbox.so (Java_io_objectbox_BoxStore_nativeCreate+92)
        #12 pc 0002d2d1  /data/app/com.myapp.app.tech.stage-lyxDCugOEC6rwPVQExvu6A==/oat/arm/base.odex (offset 0x2d000)

ObjectBox version is 1.5.0.

The crash appears only upon trying to update an app to a newer version, a fresh installation works ok, so it must have something to do with the way migrations are handled. Here's a list of the database-related changes I've made that led to a crash:

  • Replaced ToOne<DbPrice> relations with a simple reference to a Price object + appropriate converter in every database entity. Here are the classes I'm talking about:
@Entity
data class DbPrice(
        @Convert(dbType = String::class, converter = BigDecimalConverter::class)
        var value: BigDecimal,
        var currency: String,
        @Id var id: Long = 0
)
data class Price(
        val value: BigDecimal,
        val currency: String
)
class PriceConverter : PropertyConverter<Price, String> {
    override fun convertToDatabaseValue(entityProperty: Price?): String? = entityProperty?.let {
        "${it.value}|${it.currency}"
    }
    override fun convertToEntityProperty(databaseValue: String?): Price? = databaseValue?.let {
        val parsed = databaseValue.split("|")
        Price(BigDecimal(parsed[0]), parsed[1])
    }
}
  • Added a new entity called DbZone:
@Entity
data class DbZone(
        @Id(assignable = true)
        var id: Long = 0,
        val name: String? = "",
        @Convert(converter = PriceConverter::class, dbType = String::class)
        val fee: Price? = null,
        @Convert(converter = ZoneStatusConverter::class, dbType = Int::class)
        val status: Zone.Status = Zone.Status.DISABLED
)
  • Changed this:
@Entity
data class DbArea(
        var name: String,
        var parent: String,
        @Id(assignable = true) var id: Long = 0,
        var zoneId: Long?
)

to this:

@Entity
class DbArea {
    @Id(assignable = true)
    var id: Long = 0

    lateinit var name: String
    lateinit var parent: String

    lateinit var zone: ToOne<DbZone>
}

I didn't add any @Uid annotation anywhere and didn't touch the default.json file by hand. Steps to reproduce the crash in my case:

  1. Build and run an old version of the app (without the changes mentioned above), letting it save something into ObjectBox ~1-2 seconds after launch.
  2. Apply the changes mentioned above
  3. Build and run a new version of the app, installing it over the existing one.

@andrewsdv
Copy link

Am also interested in this issue. Are there any updates?

@greenrobot
Copy link
Member

We would need a new crash log (starting with *** *** *** ...) with version 2.0.0-beta2.

@ibnux
Copy link

ibnux commented Oct 1, 2018

i change ToMany to String
and now application will not start, always crash, even when i roolback before i change it

@greenrobot-team
Copy link
Member

@ibnux Do you have the same crash? If so, please attach the crash log as requested above. Otherwise please submit a new issue, preferably with an example, so we can reproduce this. -ut

@raja-baz
Copy link

raja-baz commented Nov 7, 2018

@greenrobot I have a reliable reproduction for this case in the form of this repo: https://github.com/raja-baz/objectbox-490-reproduction

Steps to reproduce:

  1. Check out commit 8a5070a28bb23f1108d60e56b181a67bd9513838
  2. Run the app
  3. Check out commit 1243aac8fa6fdf46892395cd89646592a695d916
  4. Run the app => Experience the crash

This seems to be an issue during migration when an entity which is used as a target for a relation is removed. Some additional tests show that:

  1. If the data is not populated yet, the migration will go through successfully. To test this, run the commits in this order:
    1. 17128fb36b706425377ca30eee4769133c6c8ff8
    2. 1243aac8fa6fdf46892395cd89646592a695d916
  2. If we have an intermediate migration where the relation is removed, but not the target entity, the migration also goes through fine. Run the commits in this order to test:
    1. 8a5070a28bb23f1108d60e56b181a67bd9513838
    2. 26ad20eb8aefa87c2749e58947462fcea0aad596
    3. 1243aac8fa6fdf46892395cd89646592a695d916

For now, we've decided to keep the legacy entities and not delete them to work around this issue while just not using them. Obviously this isn't ideal, but a segfault on app launch is even less ideal :P

Cheers

PS: This is on latest object box(2.1) and the crash in question is:

11-07 12:58:07.823 15770 15770 F libc    : Fatal signal 11 (SIGSEGV), code 1, fault addr 0x20 in tid 15770 (m.objectboxtest)
11-07 12:58:07.842 15794 15794 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
11-07 12:58:07.842 15794 15794 F DEBUG   : Build fingerprint: 'Android/sdk_gphone_x86_64/generic_x86_64:8.0.0/OSR1.180418.007/5071102:userdebug/dev-keys'
11-07 12:58:07.842 15794 15794 F DEBUG   : Revision: '0'
11-07 12:58:07.842 15794 15794 F DEBUG   : ABI: 'x86_64'
11-07 12:58:07.842 15794 15794 F DEBUG   : pid: 15770, tid: 15770, name: m.objectboxtest  >>> anghami.com.objectboxtest <<<
11-07 12:58:07.842 15794 15794 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x20
11-07 12:58:07.842 15794 15794 F DEBUG   : Cause: null pointer dereference
11-07 12:58:07.842 15794 15794 F DEBUG   :     rax 00007ffe8574c720  rbx 0000000000000000  rcx 0000000000000002  rdx 0000000000000000
11-07 12:58:07.842 15794 15794 F DEBUG   :     rsi 0000000000000001  rdi 0000000000000000
11-07 12:58:07.842 15794 15794 F DEBUG   :     r8  ffffffffffffffe0  r9  00007056f9a27208  r10 00007056f9a27208  r11 00007056fd1beca8
11-07 12:58:07.842 15794 15794 F DEBUG   :     r12 0000000000000000  r13 0000000000000000  r14 00007056ec1ef668  r15 00007056ec1ef500
11-07 12:58:07.843 15794 15794 F DEBUG   :     cs  0000000000000033  ss  000000000000002b
11-07 12:58:07.843 15794 15794 F DEBUG   :     rip 00007056e214e1d4  rbp 00007056f9a2dc68  rsp 00007ffe8574c230  eflags 0000000000010246
11-07 12:58:07.844 15794 15794 F DEBUG   :
11-07 12:58:07.844 15794 15794 F DEBUG   : backtrace:
11-07 12:58:07.844 15794 15794 F DEBUG   :     #00 pc 000000000008d1d4  /data/app/anghami.com.objectboxtest-W3dHK5lUXMLiGBZ028womw==/lib/x86_64/libobjectbox.so
11-07 12:58:07.844 15794 15794 F DEBUG   :     #01 pc 000000000004bad9  /data/app/anghami.com.objectboxtest-W3dHK5lUXMLiGBZ028womw==/lib/x86_64/libobjectbox.so
11-07 12:58:07.844 15794 15794 F DEBUG   :     #02 pc 000000000004d5be  /data/app/anghami.com.objectboxtest-W3dHK5lUXMLiGBZ028womw==/lib/x86_64/libobjectbox.so
11-07 12:58:07.845 15794 15794 F DEBUG   :     #03 pc 000000000004d34d  /data/app/anghami.com.objectboxtest-W3dHK5lUXMLiGBZ028womw==/lib/x86_64/libobjectbox.so
11-07 12:58:07.845 15794 15794 F DEBUG   :     #04 pc 000000000008f9d6  /data/app/anghami.com.objectboxtest-W3dHK5lUXMLiGBZ028womw==/lib/x86_64/libobjectbox.so
11-07 12:58:07.845 15794 15794 F DEBUG   :     #05 pc 000000000009416f  /data/app/anghami.com.objectboxtest-W3dHK5lUXMLiGBZ028womw==/lib/x86_64/libobjectbox.so
11-07 12:58:07.845 15794 15794 F DEBUG   :     #06 pc 0000000000090db4  /data/app/anghami.com.objectboxtest-W3dHK5lUXMLiGBZ028womw==/lib/x86_64/libobjectbox.so
11-07 12:58:07.845 15794 15794 F DEBUG   :     #07 pc 0000000000090a7f  /data/app/anghami.com.objectboxtest-W3dHK5lUXMLiGBZ028womw==/lib/x86_64/libobjectbox.so
11-07 12:58:07.845 15794 15794 F DEBUG   :     #08 pc 0000000000041f06  /data/app/anghami.com.objectboxtest-W3dHK5lUXMLiGBZ028womw==/lib/x86_64/libobjectbox.so
11-07 12:58:07.845 15794 15794 F DEBUG   :     #09 pc 000000000001b23f  /data/app/anghami.com.objectboxtest-W3dHK5lUXMLiGBZ028womw==/lib/x86_64/libobjectbox.so (Java_io_objectbox_BoxStore_nativeCreate+191)
11-07 12:58:07.845 15794 15794 F DEBUG   :     #10 pc 000000000000a532  /data/app/anghami.com.objectboxtest-W3dHK5lUXMLiGBZ028womw==/oat/x86_64/base.odex (offset 0xa000)
11-07 12:58:07.845 15794 15794 F DEBUG   :     #11 pc 0000000000000013  <unknown>

@raja-baz
Copy link

raja-baz commented Nov 7, 2018

Note that my crash seems very similar to the one @s0nerik reported but not the original one(null pointer dereference versus what looks like an exception being thrown). Would you rather I file this as a separate issue?

@greenrobot-team greenrobot-team self-assigned this Nov 13, 2018
@greenrobot-team
Copy link
Member

@raja-baz Thanks for your repro project, could verify the crash. Using this issue is fine as the original reporter has not responded.

Passed this on to the development team.
-ut

@greenrobot-team greenrobot-team added bug Something isn't working and removed need to investigate labels Nov 13, 2018
@greenrobot-team greenrobot-team changed the title nativeCreate crash Crash when removing relation and related entity Apr 1, 2019
@dillonc17
Copy link

@greenrobot , any updates on the bug fix?

I encountered similar crash as well.
After the app is published, users will encounter crash, if they update the app while the app is running (background).
However, if they clear the app (not running in background) before updating it, everything works fine.

@greenrobot-team greenrobot-team added this to the 2.4.0 milestone Sep 23, 2019
@greenrobot-team
Copy link
Member

Thanks again everyone for reporting. A fix was issued internally and will be available with the next update.

@greenrobot
Copy link
Member

This is also part of the just released version '2.4.0-RC' - would be great if you could give it a try and report back. Thank you!

@Schrobie
Copy link

@greenrobot I was having this same issue and I don't see it anymore with 2.4.0-RC

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

10 participants