Author zyasoft
Recipients Arfrever, dstromberg, jdemoor, zyasoft
Date 2015-12-27.17:37:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The underlying problem is seen in in this code snippet:

    toRead = Math.max(0, fileChannel.size() - fileChannel.position());

But per Linux's design, nearly all files in the /proc filesystem have
a file size of 0. See So this means that readAll will just return an empty ByteBuffer, which is converted to an empty string.

Note that the file is still readable; let's define a function like so:

def readall(f):
    chunks = []
    while True:
        chunk =  # completely arbitrary!
        if not chunk:
    return ''.join(chunks)

Then use it with the example provided:

>>> import os
>>> pid = os.getpid()
>>> from readall import readall
>>> f = open('/proc/{}/status'.format(pid), 'r')
>>> readall(f)
'Name:\tjava\nState:\tS (sleeping)\nTgid:\t11604\nNgid:\t0\nPid:\t11604\nPPid:\t11600\nTracerPid:\t0\nUid:\t1000\t1000\t1000\t1000\nGid:\t1000\t1000\t1000\t1000\nFDSize:\t256\nGroups:\t4 24 27 30 46 109 124 144 1000 \nNStgid:\t11604\nNSpid:\t11604\nNSpgid:\t11600\nNSsid:\t24130\nVmPeak:\t 1968928 kB\nVmSize:\t 1903392 kB\nVmLck:\t       0 kB\nVmPin:\t       0 kB\nVmHWM:\t  124500 kB\nVmRSS:\t  123520 kB\nVmData:\t 1838800 kB\nVmStk:\t     136 kB\nVmExe:\t       4 kB\nVmLib:\t   15732 kB\nVmPTE:\t     516 kB\nVmPMD:\t      24 kB\nVmSwap:\t       0 kB\nThreads:\t18\nSigQ:\t2/31534\nSigPnd:\t0000000000000000\nShdPnd:\t0000000000000000\nSigBlk:\t0000000000000000\nSigIgn:\t0000000000000000\nSigCgt:\t2000000181005ccf\nCapInh:\t0000000000000000\nCapPrm:\t0000000000000000\nCapEff:\t0000000000000000\nCapBnd:\t0000003fffffffff\nSeccomp:\t0\nCpus_allowed:\t3f\nCpus_allowed_list:\t0-5\nMems_allowed:\t00000000,00000001\nMems_allowed_list:\t0\nvoluntary_ctxt_switches:\t1\nnonvoluntary_ctxt_switches:\t2\n'

So that's an easier workaround.

Two possibilities for fixing this bug:

1. Determining that we are working with such a file. It may be sufficient to compute the abspath on the file and determine it's under /proc and we are on Linux, although that seems a lot of special casing. Maybe there's a better predicate for being special?

2. Alternatively we can just read in chunks all such files.

Such chunking will result in some more allocation ByteBuffer overhead, but this is likely a micro-optimization concern.
Date User Action Args
2015-12-27 17:37:18zyasoftsetmessageid: <>
2015-12-27 17:37:18zyasoftsetrecipients: + zyasoft, dstromberg, Arfrever, jdemoor
2015-12-27 17:37:18zyasoftlinkissue2358 messages
2015-12-27 17:37:16zyasoftcreate