AnsweredAssumed Answered

HTTP Server 4.0.2 System Crash On Recipt Of High Volume Of CGI POST Messages

Question asked by Tim Hutchinson on Jan 23, 2014
Latest reply on Sep 12, 2014 by pbanta

Hi All,

 

     I'm using the HTTP Server from RTCS 4.0.2 and have discovered a problem. When the client webpage sends a large volume of CGI POST messages the entire MQX system can be crashed. What I mean by "high volume" is I have a webpage with a gain slider on it and as it is moved it generates a CGI POST message that is about 100 bytes long. If I only allow the webpage to send one message per second there's no problem but, if I don't pace it, after a few (5, 10) seconds of continuous slider movement, MQX crashes. It's not a problem with my CGI function that process the incoming gain command (I've commented it out and just ignored these messages and the same thing happens).

 

     The main CGI function that is called when any incoming message is received reads from the socket into a temp buffer (allocated for this session), calls the appropriate function to handle the message (based on it's content), frees the memory allocated for the buffer and exits. The problem seems to occur when a new CGI POST message is received while a previous message is still being processed. Has anybody else run into a problem similar to this? When the system crashes (under debug control) I frequently observe that MQX is running the SOCK_STREAM_shutdown() function. Any thoughts on troubleshooting something likes this? Thanks for any replies!

 

Best Regards,

Tim

 

 

_mqx_int CGI_ParseMsg(HTTPSRV_CGI_REQ_STRUCT *param)
     {
     uint_32 lTotalMsgBytes, lReadLength, lBytesRead, lReadval;
     _mqx_int lRetval = 0;
     char_ptr sRecvBuffer = NULL;
     char_ptr sBufferPtr = NULL;
     //
     //----------------------------------------------------------------------------
     if(param->request_method != HTTPSRV_REQ_POST)  
          return(0);  
     //Attempt to allocate a sRecvBuffer to store the received data
     //----------------------------------------------------------------------------
     lTotalMsgBytes = param->content_length;
     sRecvBuffer = _mem_alloc(lTotalMsgBytes);
     if(sRecvBuffer == NULL)
          {
         PSERVE_LogMsg(local->cOurSlot, "CGI_ParseMsg() - Unable To Allocate sRecvBuf", gcLOGENTRY_ERROR);
        return(0);
        }

     //Read in the data until all bytes (per lTotalRecvdMsgBytes value) are received
     //----------------------------------------------------------------------------
     sBufferPtr = sRecvBuffer; //Use sBufferPtr as a movable temp pointer so sRecvBuffer can always point to buffer start
     lBytesRead = 0;
     while(param->content_length > 0)  
        {
        lReadLength = HTTPSRV_cgi_read(param->ses_handle, sBufferPtr, (lTotalMsgBytes-lBytesRead));
        param->content_length -= lReadLength;
        sBufferPtr += lReadLength;
        lBytesRead += lReadLength;
       }

     //Parse / decode the msg here
     //----------------------------------------------------------------------------
     :
     :
     :
     _mem_free(sRecvBuffer);
     return(0);
     }

Outcomes