ac2cz / FoxTelem

AMSAT Fox-1 Telemetry Decoder
GNU General Public License v3.0
52 stars 17 forks source link

Stability issue with 1.04 #176

Closed ac2cz closed 8 years ago

ac2cz commented 8 years ago

image

ac2cz commented 8 years ago

20160414112635: SoundCard: threw error: java.lang.IndexOutOfBoundsException: Attempt to read past end pointer at decoder.CircularByteBuffer.get(CircularByteBuffer.java:154) at decoder.SourceAudio.readBytes(SourceAudio.java:100) at decoder.SourceIQ.run(SourceIQ.java:249) at java.lang.Thread.run(Unknown Source)

This happens when we are getting elements from the byteBuffer:

public byte get(int i) {
        if (i > size())
            throw new IndexOutOfBoundsException("Attempt to read past end pointer");
        int p = incPointer(startPointer, i);
        return bytes[p];
    }

It is only called in one place, as part of readBytes in sourceAudio. This is being called when we want to read audio from the soundcard byteBuffer into the IQDecoder and when we want to read from the IQDecoder byteBuffer into the decoder.

At this point we have checked that size of the buffer is greater than the frameSize (2 or 4) and then we read the 2 (or 4) bytes. Inside the get method above we then make sure that i is not greater than the size(), which is calculated like below, and is subject to the same race condition as #204. So we fix it the same way and store the value of the endPointer for both checks

public int size() {
        int size = 0;
        if (endPointer >= startPointer)
            size = endPointer - startPointer;
        else {
            size = bufferSize - startPointer; // distance from start to end of the real array
            size = size + endPointer;  //  add the distance from the start to the write pointer
        }
        return size;    
    }  
ac2cz commented 8 years ago

I also saw this: image

image

20160415112658: Reading server params from: http://amsat.us/FoxTelem/server.txt java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Unknown Source) at sun.net.www.http.KeepAliveCache$1.run(Unknown Source) at sun.net.www.http.KeepAliveCache$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.net.www.http.KeepAliveCache.put(Unknown Source) at sun.net.www.http.HttpClient.putInKeepAliveCache(Unknown Source) at sun.net.www.http.HttpClient.finished(Unknown Source) at sun.net.www.http.KeepAliveStream.close(Unknown Source) at sun.net.www.MeteredStream.justRead(Unknown Source) at sun.net.www.MeteredStream.read(Unknown Source) at java.io.FilterInputStream.read(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source) at sun.nio.cs.StreamDecoder.readBytes(Unknown Source) at sun.nio.cs.StreamDecoder.implRead(Unknown Source) at sun.nio.cs.StreamDecoder.read(Unknown Source) at java.io.InputStreamReader.read(Unknown Source) at java.io.BufferedReader.read1(Unknown Source) at java.io.BufferedReader.read(Unknown Source) at java.io.Reader.read(Unknown Source) at java.util.Properties$LineReader.readLine(Unknown Source) at java.util.Properties.load0(Unknown Source) at java.util.Properties.load(Unknown Source) at common.UpdateManager.updateServerParams(UpdateManager.java:67) at common.UpdateManager.run(UpdateManager.java:277) at java.lang.Thread.run(Unknown Source) java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.addWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.execute(Unknown Source) at java.util.concurrent.AbstractExecutorService.submit(Unknown Source) at org.jtransforms.utils.ConcurrencyUtils.submit(ConcurrencyUtils.java:359) at org.jtransforms.utils.CommonUtils.cftrec4_th(CommonUtils.java:3469) at org.jtransforms.utils.CommonUtils.cftfsub(CommonUtils.java:443) at org.jtransforms.fft.DoubleFFT_1D.complexInverse(DoubleFFT_1D.java:352) at org.jtransforms.fft.DoubleFFT_1D.complexInverse(DoubleFFT_1D.java:307) at decoder.SourceIQ.inverseFFT(SourceIQ.java:443) at decoder.SourceIQ.processBytes(SourceIQ.java:350) at decoder.SourceIQ.run(SourceIQ.java:252) at java.lang.Thread.run(Unknown Source)

ac2cz commented 8 years ago

Restarted and memory usage noted as below: image

ac2cz commented 8 years ago

The error "java.lang.OutOfMemoryError: Unable to create new native thread" typically means that we have run out of stack space. Typically you can have thousands of threads, so this is a bug. I think it is the issue where an error calls the error handler in a loop. The issue is we do not see the original error. I need to debug that. We had that issue on the server recently as well.

ac2cz commented 8 years ago

This seems to be a rare issue. I have not seen it again. I am going to move it to Release 1.05 for more investigation. Ideally we will have a mechanism for users to send crash details in to the server, so we can see how common this type of issue is.