#275 crash on IOCP

For_2.0
open
nobody
5
2012-04-28
2012-04-28
fffvvvzz
No

cpp code

#include <event2/thread.h>
#include <event2/event.h>
#include <event2/buffer.h>
#include <event2/bufferevent.h>
#include <event2/listener.h>

static void
read_cb(struct bufferevent *bev, void *ctx) {
evbuffer *out = bufferevent_get_output(bev);
evbuffer *in = bufferevent_get_input(bev);
evbuffer_remove_buffer(in, out, evbuffer_get_length(in));
shutdown(bufferevent_getfd(bev), SD_SEND);
bufferevent_free(bev);
}

static void
event_cb(struct bufferevent *bev, short events, void *ctx) {
if (events & BEV_EVENT_ERROR == BEV_EVENT_ERROR) {
bufferevent_free(bev);
return;
}
if (events & BEV_EVENT_EOF == BEV_EVENT_EOF) {
bufferevent_free(bev);
return;
}
}

static void
listener_cb(struct evconnlistener *listener,
evutil_socket_t sock,
struct sockaddr *addr,
int len,
void *ptr) {
event_base *base = evconnlistener_get_base(listener);

evutil_make_socket_nonblocking(sock);
bufferevent *bev = bufferevent_socket_new(base, sock, BEV_OPT_CLOSE_ON_FREE | BEV_OPT_THREADSAFE);
bufferevent_setcb(bev, read_cb, NULL, event_cb, NULL);
bufferevent_enable(bev, EV_READ | EV_WRITE);
}

int
main(int argc, char **argv) {
WSADATA wsadata;
WSAStartup(MAKEWORD(2, 2), &wsadata);
event_config *config = event_config_new();
event_config_set_flag(config, EVENT_BASE_FLAG_STARTUP_IOCP);
evthread_use_windows_threads();
event_config_set_num_cpus_hint(config, 4);
event_base *base = event_base_new_with_config(config);
event_config_free(config);

struct sockaddr_storage addr;
int addrlen = sizeof(addr);
evutil_parse_sockaddr_port("0.0.0.0:9929", (struct sockaddr *)&addr, &addrlen);
evconnlistener_new_bind(base,
listener_cb,
NULL,
LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE,
-1,
(struct sockaddr *)&addr,
addrlen);

event_base_dispatch(base);
return 0;
}
====================
test code(python)

#!/usr/bin/env python

import socket,time,struct,sys

while True:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect(('localhost', 9929))
print "connected"
sock.send("GET / HTTP/1.0\r\n\r\n");
while True:
buf = sock.recv(4096)
print len(buf)
if len(buf) == 0:
break;
else:
print buf
except:
print sys.exc_info()
sock.close()
========================
use 2 or many tester process, server will crash
many log
[warn] Unexpected error on AcceptEx: Unknown error
[warn] Unexpected error on AcceptEx: Unknown error
[warn] Unexpected error on AcceptEx: Unknown error
[warn] Unexpected error on AcceptEx: Unknown error
[warn] Unexpected error on AcceptEx: Unknown error
and one log
[warn] fcntl(284, F_GETFL): Socket operation on nonsocket [WSAENOTSOCK ]
then crash
========================
win7
gcc (tdm-1) 4.6.1

Discussion

  • Nick Mathewson

    Nick Mathewson - 2012-04-28

    Any stack trace on that crash?

     
  • fffvvvzz

    fffvvvzz - 2012-04-28

    i am not very familiar with windows
    where is strack in windows?

    ps: compile use vc2010 crash too

     
  • fffvvvzz

    fffvvvzz - 2012-04-28

    o,stack,wait i look it

     
  • fffvvvzz

    fffvvvzz - 2012-04-28

    [warn] Unexpected error on AcceptEx: Unknown error
    [warn] Unexpected error on AcceptEx: Unknown error
    [warn] fcntl(264, F_GETFL): Socket operation on nonsocket [WSAENOTSOCK ]

    Program received signal SIGSEGV, Segmentation fault.
    bufferevent_setcb (bufev=0x0, readcb=0x401310 <read_cb(bufferevent*, void*)>,
    writecb=0, eventcb=0x40137e <event_cb(bufferevent*, short, void*)>,
    cbarg=0x0) at bufferevent.c:348
    348 BEV_LOCK(bufev);
    (gdb) bt
    #0 bufferevent_setcb (bufev=0x0,
    readcb=0x401310 <read_cb(bufferevent*, void*)>, writecb=0,
    eventcb=0x40137e <event_cb(bufferevent*, short, void*)>, cbarg=0x0)
    at bufferevent.c:348
    #1 0x00401423 in listener_cb (listener=0x2e3ad8, sock=264, addr=0x2e4291,
    len=16, ptr=0x0) at main.cpp:38
    #2 0x00407667 in accepted_socket_invoke_user_cb (dcb=0x2e4250, arg=0x2e4218)
    at listener.c:640
    #3 0x0040e1eb in event_process_deferred_callbacks (breakptr=0x2e2ca0,
    queue=0x2e2cbc) at event.c:1379
    #4 event_process_active (base=<optimized out>) at event.c:1418
    #5 event_base_loop (base=0x2e2c18, flags=0) at event.c:1604
    #6 0x0040eb1b in event_base_dispatch (event_base=0x2e2c18) at event.c:1435
    #7 0x00401521 in main (argc=1, argv=0x2e2b38) at main.cpp:64

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks