简体   繁体   中英

“Error — memory violation : Exception ACCESS_VIOLATION received” on LR controller

Scenario: We are trying to download 2500 PDFs from our website and we need to find the response time of this scenario when run with other business flows of the application. The custom code I had written for selecting and downloading PDFs dynamically worked fine for the size of 200-300 PDFs both on vugen and even on controller. But, when we ran the same script with 2500 PDFs loaded to the DB, the script worked fine on vugen, but failed running out of memory on controller. I tried running this script alone on controller for concurrent users (20) and even then it failed giving the same out of memory error.I started getting this error as soon as the concurrent users started running on the server.

I tried following things and my observations:

1. I checked the LG we are using and had no high cpu usage/memory usage at the time I got this memory error.

2. I tried turning off the logging completely and also turned off the "Generate snapshot on error".

3. I increased the network buffer size from default 12KB to a higher value around 2MB as the server was responding with THAT PDF size.

4. Also, increased JavaScript runtime memory value to a higher value but I know it's something to do with the code.

5. I have set web_set_max_html_param_len("100000");

Here is my code:

int download_size,i,m;
m=atoi(lr_eval_string("{DownloadableRecords_FundingNotices_count}"));
for(i=1;i<=m;i++)   
lr_param_sprintf("r_buf","%sselectedNotice=%s&",lr_eval_string("{r_buf}"),lr_paramarr_idx("DownloadableRecords_FundingNotices",i));
lr_save_string(lr_eval_string("{r_buf}"), "dpAllRecords");

I am not able to find what the issue with my code as it is running fine in vugen.

One thing is: it creates huge mdrv.log file to accommodate all the 2500 members in the format shown above

"%sselectedNotice=%s&" .

I need help on this.

Okay, since that did not work and I could not find the root cause, I tried modifying the code with string buffer to hold the value instead of the parameter. This time my code did not work properly and I could not get the proper formatted value resulting in my web_custom_request failing

so, here is the code with sprintf

 char *r_buf=(char *) malloc(55000); int download_size,i,m; m=atoi(lr_eval_string("{DownloadableRecords_FundingNotices_count}")); for(i=1;i<=m;i++) sprintf(r_buf,"%sselectedNotice=%s&",r_buf,lr_paramarr_idx ("DownloadableRecords_FundingNotices",i)); lr_save_string(r_buf, "dpAllRecords"); 

I also tried using this:

 lr_save_string(lr_eval_string("{r_buf}"), "dpAllRecords"); 

though it is for embedded parameters but in vain

You could try something like the below. If frees the allocated memory, something you do not do in your examples.

I changed:

  • The way r_buf is allocated
  • how r_buf is populated (doing a sprintf() into the buffer and from the buffer might not work as expected)
  • uses lr_paramarr_len()
  • FREES THE ALLOCATED BUFFER!
  • Check that the allocated buffer is big enough in the loop

Action() Code:

char *r_buf;
char buf[2048];
int download_size,i,m;

// Allocate memory
if ( (r_buf= (char *)calloc(65535 * sizeof(char))) == NULL)
{
    lr_error_message ("Insufficient memory available");
    return -1;
}
memset( buf, 0, sizeof(buf) );

m = lr_paramarr_len("DownloadableRecords_FundingNotices");

for(i=1; i<=m; i++) {
  sprintf( buf, "selectedNotice=%s&", lr_paramarr_idx("DownloadableRecords_FundingNotices",i) );

  // Check buffer is big enough to hold the new data
  if ( strlen(r_buf)+strlen(buf) > 65535 ) {
    lr_error_message("Buffer exceeded");
    lr_abort();
  }

  // Concatenate to final buffer
  strcat( r_buf, buf ); // Bugfix: This was "strcat( r_buf, "%s", buf );"
}

// Save buffer to variable
lr_save_string(r_buf, "dpAllRecords");

// Free memory
free( r_buf );

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