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.

[Android] java.lang.RuntimeException - Possible Race Condition

See original GitHub issue

I’ve just observed this Crash in the wild - i could imagine that it could be some sort of Race Condition or maybe both - onError and onCompletion - is called at a certain condition.

Fatal Exception: java.lang.RuntimeException: Illegal callback invocation from native module. This callback type only permits a single invocation from native code.
       at com.facebook.react.bridge.CallbackImpl.invoke(CallbackImpl.java:32)
       at com.zmxv.RNSound.RNSoundModule$1.onCompletion(RNSoundModule.java:81)
       at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:2538)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:135)
       at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:196)
       at java.lang.Thread.run(Thread.java:818)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:32 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
blaues0ckecommented, May 31, 2017

Faced the same issue and figured out that this only happens (so far is I could check this for now) when two ore more sounds are played at the same time. So I used the callback of play to workaround this in my js code - maybe this will help you:

../helper/Sound.js:

import Sound from 'react-native-sound';

Sound.setCategory('Ambient');

let soundPlaying = false;

const soundLoadedCallback = (error) => {
    // ...
};

const soundPlayedCallback = (success) => {
    soundPlaying = false;
};

const beep_off = new Sound('beep_off.wav', Sound.MAIN_BUNDLE, soundLoadedCallback);
const beep_on  = new Sound('beep_on.wav',  Sound.MAIN_BUNDLE, soundLoadedCallback);


export default class SoundManager {
    static allowedToPlay() {
        if (soundPlaying) {
            console.log('Prevented sound from playing');

            return false;
        }

        soundPlaying = true;

        return true;
    }

    static flashLightOff() {
        if (SoundManager.allowedToPlay()) {
            beep_off.play(soundPlayedCallback);
        }
    }

    static flashLightOn() {
        if (SoundManager.allowedToPlay()) {
            beep_on.play(soundPlayedCallback);
        }
    }

    // ...
}

So in my case I can call Sound.flashLightOn() (import Sound from '../helper/Sound';) as often as I want but it is only one sound played at the same time - this seems to workaround this issue.

0reactions
henninghallcommented, Jun 14, 2017

@henrikra there you go, submitted PR #202

Read more comments on GitHub >

github_iconTop Results From Across the Web

Possible race condition. Quick rotations result in crash. #98
run(HandlerThread.java:61) Caused by: java.lang.RuntimeException: Camera is being used after Camera.release() was called at android.hardware.
Read more >
How can we get NPE, race condition - Stack Overflow
First, let's change the name of the variable; List<Object> list=new ArrayList<>(); because "obj" is a really awful name for a variable that ...
Read more >
[android-developers] Possible race condition whlie installing an ...
I just got an interesting exception on my Galaxy Nexus while doing the usual change-compile-debug cycle with Eclipse: 01-21 02:19:03.340 E/AndroidRuntime( ...
Read more >
SDK auto-download: race condition when building two ...
This is still an issue on Android Plugin 2.3, and it happens whenever two Android builds try to download Android SDK components at...
Read more >
Compose Runtime - Android Developers
If you are using Android Studio Bumblebee Canary 4 or AGP 7.1.0-alpha04 / 7.1.0-alpha05 ... Fixed race conditions in SnapshotStateObserver causing spurratic ...
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