Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Issue 10905264: Fix race condition in NetworkChangeNotifier on Android. (Closed)

Created:
8 years, 3 months ago by Philippe
Modified:
8 years, 3 months ago
CC:
chromium-reviews, cbentzel+watch_chromium.org, darin-cc_chromium.org, jar (doing other things), pasko, pauljensen
Visibility:
Public.

Description

Fix race condition in NetworkChangeNotifier on Android. NetworkChangeNotifier::GetCurrentConnectionType() is called on any thread, including the network thread. Its implementation on Android calls some Java code (from any thread) which indirectly reads a primitive member variable set from the UI thread. The lack of synchronization could make NetworkChangeNotifier::GetCurrentConnectionType() return an out-dated result on multi-core devices. BUG=143433 Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=157804

Patch Set 1 #

Total comments: 4

Patch Set 2 : Address David's first comment #

Patch Set 3 : Store the current connection type on the native side #

Total comments: 4

Patch Set 4 : Address Marcus' comment #

Total comments: 3

Patch Set 5 : Use a lock rather than atomicops #

Total comments: 4

Patch Set 6 : Address Ryan's comments #

Total comments: 8

Patch Set 7 : Address Szymon's comments #

Total comments: 2

Patch Set 8 : Get rid of CreateJavaObject() #

Patch Set 9 : Rebase #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+112 lines, -73 lines) Patch
M net/android/java/src/org/chromium/net/NetworkChangeNotifier.java View 1 2 3 4 5 6 7 8 4 chunks +29 lines, -20 lines 0 comments Download
M net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java View 1 2 3 4 5 6 7 8 3 chunks +11 lines, -8 lines 0 comments Download
M net/android/network_change_notifier_android.h View 1 2 3 4 5 6 7 8 2 chunks +18 lines, -5 lines 0 comments Download
M net/android/network_change_notifier_android.cc View 1 2 3 4 5 6 7 8 2 chunks +51 lines, -40 lines 2 comments Download
M net/android/network_change_notifier_factory_android.h View 1 2 3 4 5 6 7 8 1 chunk +1 line, -0 lines 0 comments Download
M net/android/network_change_notifier_factory_android.cc View 1 2 3 4 5 6 7 8 1 chunk +2 lines, -0 lines 0 comments Download

Messages

Total messages: 43 (0 generated)
Philippe
8 years, 3 months ago (2012-09-14 09:00:52 UTC) #1
digit1
https://chromiumcodereview.appspot.com/10905264/diff/1/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java File net/android/java/src/org/chromium/net/NetworkChangeNotifier.java (right): https://chromiumcodereview.appspot.com/10905264/diff/1/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java#newcode79 net/android/java/src/org/chromium/net/NetworkChangeNotifier.java:79: mAutoDetectorObserver = null; Are you sure you want to ...
8 years, 3 months ago (2012-09-14 09:13:44 UTC) #2
digit1
lgtm (with philippe's remark). Thanks.
8 years, 3 months ago (2012-09-14 09:19:26 UTC) #3
digit1
On 2012/09/14 09:19:26, digit1 wrote: > lgtm (with philippe's remark). Thanks. Aarg, sorry, this was ...
8 years, 3 months ago (2012-09-14 09:26:27 UTC) #4
Philippe
https://chromiumcodereview.appspot.com/10905264/diff/1/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java File net/android/java/src/org/chromium/net/NetworkChangeNotifier.java (right): https://chromiumcodereview.appspot.com/10905264/diff/1/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java#newcode79 net/android/java/src/org/chromium/net/NetworkChangeNotifier.java:79: mAutoDetectorObserver = null; On 2012/09/14 09:13:45, digit1 wrote: > ...
8 years, 3 months ago (2012-09-14 09:27:39 UTC) #5
Philippe
On 2012/09/14 09:27:39, Philippe wrote: > https://chromiumcodereview.appspot.com/10905264/diff/1/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java > File net/android/java/src/org/chromium/net/NetworkChangeNotifier.java (right): > > https://chromiumcodereview.appspot.com/10905264/diff/1/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java#newcode79 > ...
8 years, 3 months ago (2012-09-14 11:23:56 UTC) #6
Philippe
On 2012/09/14 11:23:56, Philippe wrote: > On 2012/09/14 09:27:39, Philippe wrote: > > > https://chromiumcodereview.appspot.com/10905264/diff/1/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java ...
8 years, 3 months ago (2012-09-14 12:24:49 UTC) #7
bulach
if I understood digit's suggestion, we could try to split like: - java class works ...
8 years, 3 months ago (2012-09-14 14:26:19 UTC) #8
Philippe
On 2012/09/14 14:26:19, bulach wrote: > if I understood digit's suggestion, we could try to ...
8 years, 3 months ago (2012-09-14 14:46:30 UTC) #9
digit1
On 2012/09/14 14:26:19, bulach wrote: > if I understood digit's suggestion, we could try to ...
8 years, 3 months ago (2012-09-14 14:46:30 UTC) #10
Philippe
I've sent a new patch set addressing David's comment. The current connection type is now ...
8 years, 3 months ago (2012-09-14 15:38:22 UTC) #11
Ryan Sleevi
Please do not use AtomicOps here. Please do not use a lock either (see Chromium-dev ...
8 years, 3 months ago (2012-09-14 15:51:52 UTC) #12
bulach
thanks phillippe! a couple of suggestions below, hopefully it'll simplify the java side: http://codereview.chromium.org/10905264/diff/11001/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java File ...
8 years, 3 months ago (2012-09-14 15:51:53 UTC) #13
felipeg_google
Hi Ryan, If I read correctly the thread in Chromium-dev, the whole issue regarding locks ...
8 years, 3 months ago (2012-09-14 16:02:46 UTC) #14
felipeg_google
Sorry, sent the email too early. Could you also propose a solution that doesn't use ...
8 years, 3 months ago (2012-09-14 16:03:56 UTC) #15
digit1
On 2012/09/14 15:51:52, Ryan Sleevi wrote: > Please do not use AtomicOps here. > > ...
8 years, 3 months ago (2012-09-14 16:04:35 UTC) #16
szym
On 2012/09/14 16:04:35, digit1 wrote: > On 2012/09/14 15:51:52, Ryan Sleevi wrote: > > Please ...
8 years, 3 months ago (2012-09-14 16:10:21 UTC) #17
Philippe
It seems that there is no way other than lock/atomicops in this specific case since ...
8 years, 3 months ago (2012-09-14 16:19:28 UTC) #18
cbentzel
+pauljensen On Fri, Sep 14, 2012 at 12:19 PM, <pliard@chromium.org> wrote: > It seems that ...
8 years, 3 months ago (2012-09-14 16:26:25 UTC) #19
szym
http://codereview.chromium.org/10905264/diff/1007/net/android/network_change_notifier_android.cc File net/android/network_change_notifier_android.cc (right): http://codereview.chromium.org/10905264/diff/1007/net/android/network_change_notifier_android.cc#newcode45 net/android/network_change_notifier_android.cc:45: CheckConnectionType(new_connection_type) ? Do this jint -> int and jint ...
8 years, 3 months ago (2012-09-14 18:25:22 UTC) #20
Ryan Sleevi
On 2012/09/14 16:26:25, cbentzel wrote: > +pauljensen It is "unfortunate", but it looks like the ...
8 years, 3 months ago (2012-09-14 19:03:58 UTC) #21
pauljensen
I tend to agree that the base::subtle:: usage here is not justified because of readability, ...
8 years, 3 months ago (2012-09-14 19:53:54 UTC) #22
Ryan Sleevi
On 2012/09/14 19:53:54, pauljensen wrote: > I tend to agree that the base::subtle:: usage here ...
8 years, 3 months ago (2012-09-14 20:53:30 UTC) #23
Philippe
I uploaded a new patch set. Sorry guys for the delay, I got distracted with ...
8 years, 3 months ago (2012-09-19 17:35:14 UTC) #24
Ryan Sleevi
https://chromiumcodereview.appspot.com/10905264/diff/16001/net/android/network_change_notifier_android.cc File net/android/network_change_notifier_android.cc (right): https://chromiumcodereview.appspot.com/10905264/diff/16001/net/android/network_change_notifier_android.cc#newcode45 net/android/network_change_notifier_android.cc:45: new_connection_type : CONNECTION_UNKNOWN); nit: I feel this might read ...
8 years, 3 months ago (2012-09-19 17:43:27 UTC) #25
Philippe
http://chromiumcodereview.appspot.com/10905264/diff/16001/net/android/network_change_notifier_android.cc File net/android/network_change_notifier_android.cc (right): http://chromiumcodereview.appspot.com/10905264/diff/16001/net/android/network_change_notifier_android.cc#newcode45 net/android/network_change_notifier_android.cc:45: new_connection_type : CONNECTION_UNKNOWN); On 2012/09/19 17:43:27, Ryan Sleevi wrote: ...
8 years, 3 months ago (2012-09-19 17:57:04 UTC) #26
szym
https://chromiumcodereview.appspot.com/10905264/diff/21001/net/android/network_change_notifier_android.cc File net/android/network_change_notifier_android.cc (right): https://chromiumcodereview.appspot.com/10905264/diff/21001/net/android/network_change_notifier_android.cc#newcode64 net/android/network_change_notifier_android.cc:64: void NetworkChangeNotifier::SetConnectionType(int connection_type) { nit: make order of SetConnectionType ...
8 years, 3 months ago (2012-09-19 18:46:55 UTC) #27
Philippe
http://chromiumcodereview.appspot.com/10905264/diff/21001/net/android/network_change_notifier_android.cc File net/android/network_change_notifier_android.cc (right): http://chromiumcodereview.appspot.com/10905264/diff/21001/net/android/network_change_notifier_android.cc#newcode64 net/android/network_change_notifier_android.cc:64: void NetworkChangeNotifier::SetConnectionType(int connection_type) { On 2012/09/19 18:46:55, szym wrote: ...
8 years, 3 months ago (2012-09-19 20:57:56 UTC) #28
Ryan Sleevi
LGTM, but one question below. https://chromiumcodereview.appspot.com/10905264/diff/19002/net/android/network_change_notifier_android.cc File net/android/network_change_notifier_android.cc (right): https://chromiumcodereview.appspot.com/10905264/diff/19002/net/android/network_change_notifier_android.cc#newcode64 net/android/network_change_notifier_android.cc:64: void NetworkChangeNotifier::CreateJavaObject(JNIEnv* env) { ...
8 years, 3 months ago (2012-09-19 21:16:31 UTC) #29
Philippe
http://chromiumcodereview.appspot.com/10905264/diff/19002/net/android/network_change_notifier_android.cc File net/android/network_change_notifier_android.cc (right): http://chromiumcodereview.appspot.com/10905264/diff/19002/net/android/network_change_notifier_android.cc#newcode64 net/android/network_change_notifier_android.cc:64: void NetworkChangeNotifier::CreateJavaObject(JNIEnv* env) { On 2012/09/19 21:16:31, Ryan Sleevi ...
8 years, 3 months ago (2012-09-19 21:34:00 UTC) #30
digit1
Please always assume that JNI operations are costly, even AttachCurrentThread(). The performance of JNI operations ...
8 years, 3 months ago (2012-09-19 21:54:25 UTC) #31
Philippe
On 2012/09/19 21:54:25, digit1 wrote: > Please always assume that JNI operations are costly, even ...
8 years, 3 months ago (2012-09-19 21:57:08 UTC) #32
gone
On 2012/09/19 21:34:00, Philippe wrote: > I got rid of CreateJavaObject() since it's used only ...
8 years, 3 months ago (2012-09-19 21:57:31 UTC) #33
pasko-google - do not use
On 2012/09/19 21:54:25, digit1 wrote: > Please always assume that JNI operations are costly, even ...
8 years, 3 months ago (2012-09-19 22:26:34 UTC) #34
Philippe
On 2012/09/19 22:26:34, pasko wrote: > On 2012/09/19 21:54:25, digit1 wrote: > > Please always ...
8 years, 3 months ago (2012-09-19 22:36:13 UTC) #35
digit1
fwiw, the *current* implementation in Dalvik essentially does a pthread_getspecific(), and returns if the thread ...
8 years, 3 months ago (2012-09-19 22:36:46 UTC) #36
szym
lgtm
8 years, 3 months ago (2012-09-19 22:38:27 UTC) #37
Yaron
This seems fine but you'll have to rebase on top of http://codereview.chromium.org/10928193/.
8 years, 3 months ago (2012-09-20 00:14:42 UTC) #38
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/pliard@chromium.org/10905264/34001
8 years, 3 months ago (2012-09-20 16:49:15 UTC) #39
commit-bot: I haz the power
Change committed as 157804
8 years, 3 months ago (2012-09-20 18:52:05 UTC) #40
gone
https://chromiumcodereview.appspot.com/10905264/diff/34001/net/android/network_change_notifier_android.cc File net/android/network_change_notifier_android.cc (right): https://chromiumcodereview.appspot.com/10905264/diff/34001/net/android/network_change_notifier_android.cc#newcode44 net/android/network_change_notifier_android.cc:44: new_connection_type : CONNECTION_UNKNOWN; Just saw this when rebasing my ...
8 years, 3 months ago (2012-09-20 21:52:01 UTC) #41
szym
https://chromiumcodereview.appspot.com/10905264/diff/34001/net/android/network_change_notifier_android.cc File net/android/network_change_notifier_android.cc (right): https://chromiumcodereview.appspot.com/10905264/diff/34001/net/android/network_change_notifier_android.cc#newcode44 net/android/network_change_notifier_android.cc:44: new_connection_type : CONNECTION_UNKNOWN; On 2012/09/20 21:52:01, dfalcantara wrote: > ...
8 years, 3 months ago (2012-09-20 21:54:19 UTC) #42
pauljensen
8 years, 3 months ago (2012-09-20 22:05:25 UTC) #43
On 2012/09/20 21:54:19, szym wrote:
>
https://chromiumcodereview.appspot.com/10905264/diff/34001/net/android/networ...
> File net/android/network_change_notifier_android.cc (right):
> 
>
https://chromiumcodereview.appspot.com/10905264/diff/34001/net/android/networ...
> net/android/network_change_notifier_android.cc:44: new_connection_type :
> CONNECTION_UNKNOWN;
> On 2012/09/20 21:52:01, dfalcantara wrote:
> > Just saw this when rebasing my patch; this overloads the CONNECTION_UNKNOWN
> > type.  CONNECTION_UNKNOWN implies that there is a network connection, but
that
> > we don't know what kind it is.  Is this intentional?
> 
> I believe so. CONNECTION_NONE is used to indicate we are offline. Paul?

We'll only use the CONNECTION_UNKNOWN from line 44 when we hit NOTREACHED() in
CheckConnectionType() so that should be fine.  It should be fine to fall back on
CONNECTION_UNKNOWN anyhow.  Other targets only ever produce CONNECTION_UNKNOWN
and CONNECTION_NONE.

Powered by Google App Engine
This is Rietveld 408576698