[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] [2.0.19-stable] Infinite loop
Was able to reproduce by running the program in GDB and adding the
breakpoints at event.c:2476 and continuing from there.
So the heap has same event at multiple positions which can cause the
event in heap to have min_heap_idx = -1. Here is the current heap
$66 = {
p = 0x63b890,
n = 19,
a = 32
}
(gdb) p base->timeheap.p[0]
$46 = (struct event *) 0x6024c0
(gdb) p base->timeheap.p[1]
$47 = (struct event *) 0x605190
(gdb) p base->timeheap.p[2]
$48 = (struct event *) 0x604c90 [a]
(gdb) p base->timeheap.p[3]
$49 = (struct event *) 0x604790
(gdb) p base->timeheap.p[4]
$50 = (struct event *) 0x604290 [b]
(gdb) p base->timeheap.p[5]
$51 = (struct event *) 0x603d90 [y]
(gdb) p base->timeheap.p[6]
$52 = (struct event *) 0x603890 [z]
(gdb) p base->timeheap.p[7]
$53 = (struct event *) 0x602e90
(gdb) p base->timeheap.p[8]
$54 = (struct event *) 0x603390
(gdb) p base->timeheap.p[9]
$55 = (struct event *) 0x602990 [x]
(gdb) p base->timeheap.p[10]
$56 = (struct event *) 0x604290 [b]
(gdb) p base->timeheap.p[11]
$57 = (struct event *) 0x602990 [x]
(gdb) p base->timeheap.p[12]
$58 = (struct event *) 0x603d90 [y]
(gdb) p base->timeheap.p[13]
$59 = (struct event *) 0x604c90 [a]
(gdb) p base->timeheap.p[14]
$60 = (struct event *) 0x603890 [z]
Not sure what is causing this corrupted heap state.
#include <stdlib.h>
#include <stdio.h>
#include <evhttp.h>
#include <event2/event.h>
#include <event2/buffer.h>
#include <event2/http.h>
#include <string.h>
#define MAX_CONN 10
void http_req_done(struct evhttp_request *req, void *ctx) {
printf("Done\n");
}
void http_req(struct event_base *base, struct evhttp_connection *evcon, char *uri, char *host, char *data, size_t bytes) {
struct evhttp_request *req;
struct evbuffer *output_buffer;
req = evhttp_request_new(http_req_done, base);
if(req == NULL) {
printf("req creation failed\n");
return;
}
evhttp_add_header(req->output_headers, "Host", host);
evhttp_add_header(req->output_headers, "Connection", "close");
char buf[16]={0};
evbuffer_add(req->output_buffer, data, bytes);
evutil_snprintf(buf, sizeof(buf)-1, "%lu", (unsigned long)bytes);
evhttp_add_header(req->output_headers, "Content-Type", "application/json");
evhttp_add_header(req->output_headers, "Accept", "application/json");
evhttp_add_header(req->output_headers, "Content-Length", buf);
int returnValue = evhttp_make_request(evcon, req, EVHTTP_REQ_POST , uri);
if(returnValue != 0) {
printf("req failed\n");
return;
}
}
int main() {
struct event_base *base;
base = event_base_new();
struct evhttp_connection *evcon_pool[MAX_CONN];
int i=0;
while( i < MAX_CONN) {
evcon_pool[i] = evhttp_connection_base_new(base, NULL, "1.1.1.1", 8888);
if(evcon_pool[i] == NULL) {
printf("connection setup failed\n");
}
evhttp_connection_set_retries(evcon_pool[i], 5);
evhttp_connection_set_timeout(evcon_pool[i], 5);
i++;
}
i=0;
int j=0;
while(j < 10) {
while( i < 100 ) {
char *data = "blah blah blah! more blah";
http_req(base, evcon_pool[i%MAX_CONN], "/test", "1.1.1.1", data,strlen(data));
i++;
}
event_base_dispatch(base);
j++;
sleep(1);
}
}