catid / siamese

Siamese : Infinite-Window Streaming Erasure Code (HARQ)
BSD 3-Clause "New" or "Revised" License
48 stars 5 forks source link

siamese_decode crashing at Decoder::DecodeCheckedRegion() #4

Closed fmiceli24 closed 4 years ago

fmiceli24 commented 4 years ago

Hi Chris,

I am getting a crash in the decode function at Decoder::DecodeCheckedRegion().

It does not happen all the time and, if it happens, it does at the beginning of my program (20 seconds in, aproximately) and after successfully decoding a few times (recovered more than 30 packages).

It is a multi-threaded application and I am protecting the decoder with a mutex.

The rest of the times that the crash does not happen I can execute the app for as much time as I want.

Any clue as to why this function could cause a segmentation fault?

fmiceli24 commented 4 years ago

According to my tests the crash only happens when I use Xcode's Network limiter to introduce loss to the channel.

I have tested on a lossy network several times but the crash has not occurred.

fmiceli24 commented 4 years ago

Here is the code of my FEC handler:

void Receiver::handleFEC(int arrivalT, std::size_t bytes_recibidos, std::shared_ptr<unsigned char> readBuff)
{
    const unsigned char* readBuffer = readBuff.get();
    boost::unique_lock<boost::mutex> lock(FECmtx); //Lock from here to the end of the function.
    int sqNum, timestamp, departureT, packetNum;
    SiameseResult siameseResult;

    //1. Feed the decoder
    if ((readBuffer[FEC_TYPE_IDX] & 0x1) == 0x0){// Original

        SiameseOriginalPacket original;
        original.Data = &readBuffer[NALU_SIZE_IDX];
        original.DataBytes = bytes_recibidos - FEC_HEADER; 
        original.PacketNum = packetNum;
        SiameseResult siameseResult = siamese_decoder_add_original(decoder, &original);
        //Here I have code to process the packet.
    }
    else {//Recovery
        if (FECEnabled){
            SiameseRecoveryPacket recovery;
            recovery.Data = &readBuffer[PACKET_N_IDX]; //Recovery packets have its payload after the FecTypeIdx
            recovery.DataBytes = bytes_recibidos - PACKET_N_IDX;
            SiameseResult siameseResult = siamese_decoder_add_recovery(decoder, &recovery);
            if (siameseResult == SiameseResult::Siamese_Success){
                //Check if decoder ready
                while (siamese_decoder_is_ready(decoder) == SiameseResult::Siamese_Success)
                {
                    SiameseOriginalPacket *decodedArray;
                    unsigned int count = 0;
                    siameseResult = siamese_decode(decoder, &decodedArray, &count);
                    if (siameseResult == SiameseResult::Siamese_Success)
                    {
                        //2.1. Fetch packets (they are ordered but might be skipped)
                        for (int i = 0; i < count; ++i)
                        {
                            shared_ptr<unsigned char> next(new unsigned char[MSP]);
                            unsigned char *aux_next = next.get();
                            memcpy(&aux_next[NALU_SIZE_IDX], decodedArray[i].Data, decodedArray[i].DataBytes);
                            //Here I have code to process the packet.
                        }
                    }
                }
            }
        }
    }
}
fmiceli24 commented 4 years ago

Nevermind. Bug was elsewhere on my code.

Thanks for such a great piece of software.

Closing the issue...