[
https://issues.apache.org/jira/browse/CB-7104?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14057854#comment-14057854
]
Nolan Lawson commented on CB-7104:
----------------------------------
I believe I'm running into the same issue on Cordova 3.5.0.
I'm working on the [SQLite
Plugin|https://github.com/brodysoft/Cordova-SQLitePlugin], and currently
everything's groovy until we try to do processing of SQLite queries on a
background thread (which is kind of useful, since otherwise it [blocks the main
UI thread and gives
warnings|https://github.com/brodysoft/Cordova-SQLitePlugin/issues/74]).
As far as I've been able to track this down in the code, there's a race
condition where the Java->JS callback code gets to [this
line|https://github.com/apache/cordova-android/blob/9300e97d2b58455c60b74cdf5e758c7c757ba691/framework/src/org/apache/cordova/NativeToJsMessageQueue.java#L320],
but then the corresponding receiver at [this line in the
JS|https://github.com/apache/cordova-android/blob/9300e97d2b58455c60b74cdf5e758c7c757ba691/framework/assets/www/cordova.js#L945]
doesn't receive the callback.
It occurs very rarely, but with our unit tests suite, I can repro it
consistently within a few seconds.
*Steps to reproduce:*
[Here|https://github.com/brodysoft/Cordova-SQLitePlugin/commit/13d22b3bcd786a3b388d64cece86c7273d593bf5]
is an example of working code (current master).
And
[here|https://github.com/nolanlawson/Cordova-SQLitePlugin/commit/0955c3e02c7e6a873d361105be2d1216224bb6c6]
is an example of a minimal change that repros the bug.
Check out the code, then simply run `./bin/test.sh android` with an Android
device attached. You need `cordova` and `coffee` installed; the script will
tell you what to do.
1. When the app launches, you'll see a QUnit test suite.
2. When the tests pass (142 out of 142 passed), scroll down to the last test
and hit "Rerun"
3. When that test completes, hit the back button.
4. Repeat 2-4 until the UI shows not all tests completed (see screenshot below)
indicating that the callback didn't return.
Notice that the working code never freezes, whereas the non-working code
occasionally does.
Note about the code: I'm using a single background thread, because otherwise
the Android flavor of SQLite tends to complain if you try to access it from
multiple threads.
*Environments*
I was able to repro this on Android 4.4.2 (Nexus 5, CyanogenMod 3.4.0) and
Android 4.2.2 (Galaxy Nexus, CyanogenMod 3.0.31).
> Plugin results not transmitted back to devices (specially Samsung S4 and S5)
> ----------------------------------------------------------------------------
>
> Key: CB-7104
> URL: https://issues.apache.org/jira/browse/CB-7104
> Project: Apache Cordova
> Issue Type: Bug
> Components: Android
> Affects Versions: 3.3.0
> Reporter: HÃ¥kon Nilsen
> Priority: Blocker
> Labels: patch
>
> Our app relies heavily on Cordova plugins for communicating between
> JavaScript and native, and on certain devices these messages are not
> consistently sent back to the JavaScript API.
> I've tracked it down to a problem with webView.setNetworkAvailable()-usage in
> NativeToJsMessageQueue.java, and I have a suggestion for a fix.
> The problem with the current setup of (3.3.0) of NativeToJsMessageQueue seems
> to be that the online flag is toggled every time a plugin is fired, while
> webView.setNetworkAvailable(online) is only fired if the queue has messages.
> Since not all plugins have messages, the online flag can be toggled twice,
> and the online flag will be i.e. false for each time the command is run -
> which means Cordova won't send any messages.
> On Samsung S4 and S5 the hideKeyboard-event is slower or faster than other
> devices, which results in a doble toggle of the online flag. This leads to
> the following command being sent when there is a message in the queue:
> webView.setNetworkAvailable(false); // first message
> webView.setNetworkAvailable(false); // second message, which is not being sent
> webView.setNetworkAvailable(false); // third message, which will be sent
> For us it has been a terrible blocker, and I've made a change to the
> OnlineEventsBridgeMode in NativeToJsMessageQueue.java that addresses this.
--
This message was sent by Atlassian JIRA
(v6.2#6252)