question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SIGSEGV on Android 7

See original GitHub issue

Issue

After updating my application I faced a lot of crashes on android 7 devices. I couldn’t reproduce it on my nexus or on the emulator so I bought one of the crashing devices. After spending half of the day I finally managed to find the root cause and I can reproduce it in a hello world project.

Sample

class MainActivity : Activity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        CoroutineScope(SupervisorJob() + Dispatchers.Main).launch {
            while (true) {
                combine(flowOf(Unit), flowOf(Unit)) { _ -> Unit }.collect()
            }
        }
    }
}

Crash

This leads to a sigsegv

    Flags: 0x28c8bf46
    Package: com.example.weirdcrash v1 (1.0)
    Foreground: Yes
    Build: TCL/5009D/U5A_PLUS_3G:7.0/NRD90M/5009D_ALWE_V2.9_20180529:user/release-keys
    
    *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    Build fingerprint: 'TCL/5009D/U5A_PLUS_3G:7.0/NRD90M/5009D_ALWE_V2.9_20180529:user/release-keys'
    Revision: '0'
    ABI: 'arm'
    pid: 29639, tid: 29639, name: mple.weirdcrash  >>> com.example.weirdcrash <<<
    signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x15608
        r0 00015000  r1 12d35700  r2 00000002  r3 00000000
        r4 af58a6d8  r5 12d31ee0  r6 12d37280  r7 00000000
        r8 12d35700  r9 ac684400  sl 12cb0a90  fp 12d33bf8
        ip bef2f84c  sp bef2f8b0  lr 9901f5ef  pc 9901f608  cpsr 000f0030
    
    backtrace:
        #00 pc 00000608  /dev/ashmem/dalvik-jit-code-cache (deleted)
        #01 pc 000005ed  /dev/ashmem/dalvik-jit-code-cache (deleted)
     29639

I currently see about 1200 affected users…

Versions

'com.android.tools.build:gradle:3.6.0-beta04'
"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2"
"org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2"

Affected Devices

image image image image image

Note

Take a look at the last crash, maybe that’s an indicator for what’s going wrong. That one is no native crash but an android 7 only issue.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
PaulWoitaschekcommented, Mar 30, 2020

I have written a non-rx version:

/**
 * Because of a bug in android 7 we can't use the regular combine functions and have to use our own.
 * @see [https://github.com/Kotlin/kotlinx.coroutines/issues/1683]
 */
@PublishedApi
internal object UnInitialized

@PublishedApi
internal inline fun <T, R> combine(vararg sources: Flow<T>, crossinline transform: suspend (List<T>) -> R): Flow<R> {
  return channelFlow {
    val values = Array<Any?>(sources.size) { UnInitialized }
    coroutineScope {
      sources.forEachIndexed { index, flow ->
        launch {
          flow.collect { value ->
            values[index] = value
            if (values.all { it !== UnInitialized }) {
              @Suppress("UNCHECKED_CAST")
              send(transform(values.toList() as List<T>))
            }
          }
        }
      }
    }
  }
}
0reactions
qwwdfsadcommented, Aug 3, 2020

@mhernand40 Unfortunately, we do not know. The stable reproducer is required in order to check such a hypothesis

Read more comments on GitHub >

github_iconTop Results From Across the Web

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR) - Nougat ...
I get signal 11 (SIGSEGV), code 1 (SEGV_MAPERR) native crashes. ... What is interesting the problem occurs only on Android 7.0 and 7.1....
Read more >
Diagnosing Native Crashes
Making code unreadable causes intentional and unintentional reads into memory segments marked execute-only to throw a SIGSEGV with code ...
Read more >
[#QTBUG-57922] QNetworkAccessManager crashes with ...
QNetworkAccessManager form 5.8.0 RC crushes with SIGSEGV on Android 7 when executing connectToHostEncrypted, get, put or post commands.
Read more >
Segmentation Fault (SIGSEGV) vs Bus Error (SIGBUS)
1) Segmentation Fault (also known as SIGSEGV and is usually signal 11) occur when the program tries to write/read outside the memory allocated ......
Read more >
[INTERNAL] SIGSEGV on endTransaction with rollback ...
setTransactionSuccessful()" causes a "A/libc: Fatal signal 11 (SIGSEGV), code 1", but only on a Motorola MotoG5 with Android 7. Not reproducable in Simulator ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found