connections are not released in http.c

Ilan Aelion <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Organization Dimoco
Message-ID <[email protected]>
Hi all, 

I'm running Kannel 1.3.1 (cvs-20040706) on SuSE 9.1 (linux 2.6.5-7.95-smp) on 
a dual processor machine. I'm using the fakesmsc test program to dispatch GET 
requests from the smsbox to a trivial application returning a fixed response 
(based on the sendsms_thread function in smsbox.c). If I set the delay on the 
fakesms lower than a certain limit, I get a constant memory usage increase 
both in the test program and in the smsbox itself. This memory is not 
released after stopping the fakesmsc. 

checking the http.c code, I found connections are created and added to the 
connection pool, but are only released on shutdown. 

Am I missing something here? In particular, is there a way to make the smsbox 
close connections, or limit the connection cache size?

TIA,
- Ilan

    ****************************************************************

fakesmsc commandline:

> fakesmsc -m 10000 -r 1 -v 1 -i 0.001 -H 192.168.0.150 "201 300 text testhttp 
testing"

    ****************************************************************

These are the relevant lines in the kannel.conf:

group = sms-service
keyword = testhttp
get-url = 
http://192.168.0.145:8080/testapp?from=%p&to=%P&smsc=%i&keyword=%k&text=%r
accept-x-kannel-headers = true
max-messages = 1
concatenation = true

    ****************************************************************


Here's the test program I'm using. 


#include "stdio.h"
#include "signal.h"
#include "gwlib/gwlib.h"
#include "gwlib/http.h"

int run, port;
int delay_factor;

void client_thread(void *arg)
{
    HTTPClient *client;
    Octstr *ip, *url, *body, *answer;
    List *hdrs, *args, *reply_hdrs;
    int status = HTTP_OK;
	int i, j;

    reply_hdrs = http_create_empty_headers();
    http_header_add(reply_hdrs, "Content-type", "text/html");
    http_header_add(reply_hdrs, "Pragma", "no-cache");
    http_header_add(reply_hdrs, "Cache-Control", "no-cache");

	answer = octstr_create("greetings\n");

    while (run) {
    	client = http_accept_request(port, &ip, &url, &hdrs, &body, 
	    	    	    	     &args);
	if (client == NULL)
	    break;

    octstr_destroy(ip);
    octstr_destroy(url);
    http_destroy_headers(hdrs);
    octstr_destroy(body);
    http_destroy_cgiargs(args);
	
    http_send_reply(client, status, reply_hdrs, answer);

	/* sophisticated delay loop */
	for (i = 0; i < delay_factor; i++)
		for (j = 0; j < delay_factor; j++);
    }
    octstr_destroy(answer);

    http_destroy_headers(reply_hdrs);
}

static void sigterm(int signo) 
{
	printf("test_serve signalled with %d\n", signo);
	run = 0;
	http_close_all_ports();
	gwlib_shutdown();
	debug("test.gwlib", 0, "Signal %d received, quitting.", signo);
}

int main(int argc, char *argv[])
{
	struct sigaction act;
	int ssl = 0;
	long thread;

	gwlib_init();

	act.sa_handler = sigterm;
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	sigaction(SIGTERM, &act, NULL);

	delay_factor =  argc > 1 ? atoi(argv[1]) : 0;

	port = 8080;
	run = 1;

	if (http_open_port(port, ssl) == -1)
	{
		printf("server won\'t start\n");
		exit(1);
	}

	thread = gwthread_create(client_thread, NULL);
	gwthread_join(thread);

	return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.