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 O StrictMode: Untagged socket detected

See original GitHub issue

If we use StrictMode with VmPolicy detectAll() in Android O (Preview 6) we get errors in logcat like this:

08-23 14:41:03.439 E/StrictMode: null
                                 java.lang.Throwable: Untagged socket detected; use TrafficStats.setThreadSocketTag() to track all network usage
                                     at android.os.StrictMode.onUntaggedSocket(StrictMode.java:2010)
                                     at com.android.server.NetworkManagementSocketTagger.tag(NetworkManagementSocketTagger.java:78)
                                     at libcore.io.BlockGuardOs.tagSocket(BlockGuardOs.java:47)
                                     at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:310)
                                     at libcore.io.IoBridge.socket(IoBridge.java:667)
                                     at java.net.PlainSocketImpl.socketCreate(PlainSocketImpl.java:116)
                                     at java.net.AbstractPlainSocketImpl.create(AbstractPlainSocketImpl.java:98)
                                     at java.net.Socket.createImpl(Socket.java:484)
                                     at java.net.Socket.getImpl(Socket.java:547)
                                     at java.net.Socket.setSoTimeout(Socket.java:1175)
                                     at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.java:221)
                                     at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:149)
                                     at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:195)
                                     at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:121)
                                     at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:100)
                                     at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
                                     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
                                     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
                                     at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
                                     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
                                     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
                                     at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
                                     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
                                     at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120)
                                     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
                                     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
                                     at <internal>
                                     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
                                     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
                                     at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:211)
                                     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
                                     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
                                     at <internal>
                                     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
                                     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
                                     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185)
                                     at okhttp3.RealCall.execute(RealCall.java:69)
                                     at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
                                     at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:91)
                                    at <internal>
                                     at <internal>
                                     at io.reactivex.internal.operators.observable.ObservableCreate.subscribeActual(ObservableCreate.java:40)
                                     at io.reactivex.Observable.subscribe(Observable.java:10903)
                                     at io.reactivex.internal.operators.observable.ObservableObserveOn.subscribeActual(ObservableObserveOn.java:45)
                                     at io.reactivex.Observable.subscribe(Observable.java:10903)
                                     at io.reactivex.internal.operators.observable.ObservableDoOnEach.subscribeActual(ObservableDoOnEach.java:42)
                                     at io.reactivex.Observable.subscribe(Observable.java:10903)
08-23 14:41:03.440 E/StrictMode:     at io.reactivex.internal.operators.observable.ObservableDefer.subscribeActual(ObservableDefer.java:39)
                                     at io.reactivex.Observable.subscribe(Observable.java:10903)
                                     at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
                                     at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:452)
                                     at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
                                     at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
                                     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
                                     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
                                     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                                     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                                     at java.lang.Thread.run(Thread.java:764)

From what I can tell, this happens because the sockets are untagged - is that something okhttp might want to support?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:89
  • Comments:24 (3 by maintainers)

github_iconTop GitHub Comments

64reactions
ojw28commented, Sep 11, 2017

there would be negligible value to having such a tag

Suppose a dev team sets penaltyDeath() for all strict mode violations in their internal app builds, so as to make it really obvious when a strict mode violation is introduced. OkHttp currently causes such app builds to die. I think “fixing” this has value in itself, even if the tag is arbitrary and adds no further value. So it seems worthwhile to set an arbitrary tag just to make the strict mode violation go away?

22reactions
saschak42commented, Sep 6, 2018

Any news on this issue? We use several dependencies which also have the problem. Waiting until every dependency implements this workaround isn’t suitable. A solution in okhttp itself would definitely be the preferred way.

Since PR #1101 is already merged, are there any plans for the next release? @yschimke @JakeWharton

Read more comments on GitHub >

github_iconTop Results From Across the Web

StrictMode java.lang.Throwable: Untagged socket detected
There are a couple of ways to handle this exception. First, you have to inspect the stack trace and make sure it is...
Read more >
UntaggedSocketViolation - Android Developers
Returns an array containing all of the exceptions that were suppressed, typically by the try -with-resources statement, in order to deliver this exception....
Read more >
Developers - Android O StrictMode: Untagged socket detected -
Android O StrictMode : Untagged socket detected.
Read more >
core/java/android/os/strictmode/UntaggedSocketViolation.java
You may obtain a copy of the License at ... package android.os.strictmode; ... super("Untagged socket detected; use TrafficStats.setTrafficStatsTag() to ".
Read more >
Walk through hell with Android StrictMode | by Elye - Medium
Android provided developer a tool i.e. Strict Mode , that would help to detect if our code have some slow operation (e.g. disk...
Read more >

github_iconTop Related Medium Post

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