简体   繁体   中英

Android VpnService write packet error - no buffer space available

I'm writing UDP packets to a VpnService instance in Android, but I intermittently get errors like:

java.io.IOException: write failed: ENOBUFS (No buffer space available)
at libcore.io.IoBridge.write(IoBridge.java:455)
at java.io.FileOutputStream.write(FileOutputStream.java:187)
at java.io.OutputStream.write(OutputStream.java:82)

There is only a single DatagramSocket that is used to send and receive packets, so I don't think I'm leaking memory. I also checked my heap usage, which remains stable at 10-12 MB. I don't get this error with TCP packets I'm transferring. Any suggestions?

I just hit this problem in my own VPN implementation ( open source , if anybody wants a working example).

In my case, this was because I was writing TCP packets back to the VPN interface that were larger than expected, because my code wasn't properly handling the max segment size.

This wasn't due to some general purpose buffer waiting to flush, so packets that were too large for the receiving application would fail with ENOBUFS forever.

Although I can't find it documented anywhere, I expect this is the cause in general: you'll hit an ENOBUFS if you try to write any packet to the VPN that's individually larger than what the VPN expects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM