Android error: Failed to read input channel file descriptors from package

I made an Android application that works something like this:

  • The application contacts the web service and transfers information (not files)
  • I can switch to another screen using Intent and startActivity

Unfortunately, sometimes the application crashes with the following error in different actions:

 java.lang.RuntimeException: Could not read input channel file descriptors from parcel. at android.view.InputChannel.nativeReadFromParcel(Native Method) at android.view.InputChannel.readFromParcel(InputChannel.java:135) at android.view.IWindowSession$Stub$Proxy.add(IWindowSession.java:523) at android.view.ViewRootImpl.setView(ViewRootImpl.java:481) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:301) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:215) at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:140) at android.view.Window$LocalWindowManager.addView(Window.java:537) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2507) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1986) at android.app.ActivityThread.access$600(ActivityThread.java:123) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4424) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method) 

But I do not know what this error means, because I do not work with files. Any ideas?

+7
source share
3 answers

This question looks the same as β€œ Failed to read input channel file descriptors from a section that was (incorrectly) closed off topic. It is also more or less the same as Failed to read input channel file descriptors from the report Unfortunately, these questions did not receive a satisfactory (and fairly general) answer, so I’ll try anyway.

File descriptors are used in several places in Android:

  • Sockets (yes, open network connections are also β€œfiles”);
  • Actual files (not necessarily files on disks, can also be instances of android.os.MemoryFile );
  • Channels - Linux uses them everywhere, for example, trying to open a channel that led to your exception was probably required to send input events between the IME process (keyboard) and your application.

All descriptors obey the general maximum limit ; when this number is exceeded, your application begins to experience serious problems. In this case, the best scenario is to use the die process, because otherwise the kernel would run out of memory (file descriptors are stored in kernel memory).

You may have problems closing the descriptors (files, network connections). You should close them as soon as possible. You may also have problems with memory leaks - objects are not garbage collected when they should (and some of the leaks may, in turn, contain file descriptors).

Your own code should not be guilty, the libraries that you use, and even some system components, may have errors leading to memory leaks and file descriptor leaks. I recommend that you use Square Leak Canary , a simple and convenient library for automatically detecting leaks (well, at least the memory leaks that are most common).

+12
source

The failure can be caused by too much load on the device, which leads to the fact that the system runs out of file descriptors. Although you cannot declare files or file descriptors in your code, they are used internally and the number of used increases with the number of actions, services, threads, etc. The stack trace is very similar to many stack traces in the AOSP 32470 issue . The first step to solving the problem may be to look at your project to confirm that you are not creating an excessive number of threads / actions / services, etc.

You can also try running StrictMode.VmPolicy to find out the resource leak.

+1
source

In my case, the cause of the problem is creating too many threads. I created more than a thousand queries in a loop incorrectly, finally causing this problem. People who face this problem should avoid this situation.

0
source

All Articles