Re: [Libevent-users] help about an error message

2013-03-26 Thread Azat Khuzhin
Hi,

On Tue, Mar 26, 2013 at 2:22 AM, sven falempin  wrote:
> using libevent2 (libevent-2.0.21-stable) i create this log:
>
> [warn] event_del: event has no event_base set.
> [err] event_assign called on an already added event 0x84de9e4 (events: 0x0,
> fd: 0, flags: 0x0)
>
> using this code:
>
> void connection::listen_write_event() {
>   int rc = 0;
>   if (fd == -1) return;
>   if (is_listening_write) return;
>   is_listening_write = 1;
> #ifdef DEBUG
>   fprintf(stderr,"%d:%08X, LISTEN WRITING\n",fd, (unsigned
> int)pthread_self());
> #endif
>   event_del(&_sock_ev_write);

What is "_sock_ev_write" how you initialize it?
On stack I suppose?

Why do you call event_del() if you don't set event_base for it?
You install base, on the next line.

>   rc = event_assign(&_sock_ev_write, s->get_evt_base(),
> fd, EV_WRITE,
> server::con_ready_pattern, this);
>   if (rc == 0)
> event_add(&_sock_ev_write, NULL);
>   else
> syslog( LOG_CRIT, "%d:cannot create write event",fd);
> }
>
> i cannot supress the warn even if i put an event base (probably
> missunderstood the doc)

Did saw this? It has all that you need, for now, I think.
http://www.wangafu.net/~nickm/libevent-book/Ref4_event.html

>
> i declared
> struct event_base * evt_base; as a global
>
> and get it init:
>
> #ifdef DEBUG
>   event_enable_debug_mode();
> #endif
>   evthread_use_pthreads();
>   gconf.evt_base = event_base_new();
>   if ( gconf.evt_base == NULL ) {
> syslog( LOG_ERR, "cannot allocate base for %s:%d", gconf.ip,
> gconf.port);
> return 1;
>   }
>
> then used it everywhere
>
>
> to create the bug i connect frenzy to the server using a while true;
>
> Notice: if the program do not close the FD i exhaust the files desc before
> reaching the bug.
>
> --
> -
> () ascii ribbon campaign - against html e-mail
> /\



--
Respectfully
Azat Khuzhin
Primary email a3at.m...@gmail.com
***
To unsubscribe, send an e-mail to majord...@freehaven.net with
unsubscribe libevent-usersin the body.


Re: [Libevent-users] help about an error message

2013-03-26 Thread sven falempin
On Tue, Mar 26, 2013 at 10:04 AM, Azat Khuzhin wrote:

> Hi,
>
> On Tue, Mar 26, 2013 at 2:22 AM, sven falempin 
> wrote:
> > using libevent2 (libevent-2.0.21-stable) i create this log:
> >
> > [warn] event_del: event has no event_base set.
> > [err] event_assign called on an already added event 0x84de9e4 (events:
> 0x0,
> > fd: 0, flags: 0x0)
> >
> > using this code:
> >
> > void connection::listen_write_event() {
> >   int rc = 0;
> >   if (fd == -1) return;
> >   if (is_listening_write) return;
> >   is_listening_write = 1;
> > #ifdef DEBUG
> >   fprintf(stderr,"%d:%08X, LISTEN WRITING\n",fd, (unsigned
> > int)pthread_self());
> > #endif
> >   event_del(&_sock_ev_write);
>
> What is "_sock_ev_write" how you initialize it?
> On stack I suppose?
>
> Why do you call event_del() if you don't set event_base for it?
> You install base, on the next line.
>

_sock_ev_write is a member of connection.

each client get a connection object created.
the program listen the write event after having writing to socket.
so i delete the event set the previous time.

i do not want use EV_PERSIST (because i read in another thread)



> >   rc = event_assign(&_sock_ev_write, s->get_evt_base(),
> > fd, EV_WRITE,
> > server::con_ready_pattern, this);
> >   if (rc == 0)
> > event_add(&_sock_ev_write, NULL);
> >   else
> > syslog( LOG_CRIT, "%d:cannot create write event",fd);
> > }
> >
> > i cannot supress the warn even if i put an event base (probably
> > missunderstood the doc)
>
> Did saw this? It has all that you need, for now, I think.
> http://www.wangafu.net/~nickm/libevent-book/Ref4_event.html
>
> Never saw
i was used to libevent 1
when i switch to 2 i didnt saw the all buffered managment for multithreada
:-(


>  >
> > i declared
> > struct event_base * evt_base; as a global
> >
> > and get it init:
> >
> > #ifdef DEBUG
> >   event_enable_debug_mode();
> > #endif
> >   evthread_use_pthreads();
> >   gconf.evt_base = event_base_new();
> >   if ( gconf.evt_base == NULL ) {
> > syslog( LOG_ERR, "cannot allocate base for %s:%d", gconf.ip,
> > gconf.port);
> > return 1;
> >   }
> >
> > then used it everywhere
> >
> >
> > to create the bug i connect frenzy to the server using a while true;
> >
> > Notice: if the program do not close the FD i exhaust the files desc
> before
> > reaching the bug.
> >
> > --
> >
> -
> > () ascii ribbon campaign - against html e-mail
> > /\
>
>
>
> --
> Respectfully
> Azat Khuzhin
> Primary email a3at.m...@gmail.com
> ***
> To unsubscribe, send an e-mail to majord...@freehaven.net with
> unsubscribe libevent-usersin the body.
>



-- 
-
() ascii ribbon campaign - against html e-mail
/\


Re: [Libevent-users] help about an error message

2013-03-26 Thread Nick Mathewson
On Tue, Mar 26, 2013 at 10:41 AM, sven falempin  wrote:
> Never saw
> i was used to libevent 1
> when i switch to 2

My guess is that you're setting up these events before constructing an
event_base or calling event_init. That might have worked with libevent
1, but in libevent 2, you need to make sure every event has an
event_base.  The best way is to call one of the functions that creates
an event_base explicitly, and then use event_new or event_assign to
construct your events -- but you can still use event_init() and
event_set() like you did before, just so long as you call event_init()
first.

-- 
Nick
***
To unsubscribe, send an e-mail to majord...@freehaven.net with
unsubscribe libevent-usersin the body.


Re: [Libevent-users] help about an error message

2013-03-26 Thread sven falempin
On Tue, Mar 26, 2013 at 10:44 AM, Nick Mathewson wrote:

> On Tue, Mar 26, 2013 at 10:41 AM, sven falempin 
> wrote:
> > Never saw
> > i was used to libevent 1
> > when i switch to 2
>
> My guess is that you're setting up these events before constructing an
> event_base or calling event_init. That might have worked with libevent
> 1, but in libevent 2, you need to make sure every event has an
> event_base.  The best way is to call one of the functions that creates
> an event_base explicitly, and then use event_new or event_assign to
> construct your events -- but you can still use event_init() and
> event_set() like you did before, just so long as you call event_init()
> first.
>
> --
> Nick
> ***
> To unsubscribe, send an e-mail to majord...@freehaven.net with
> unsubscribe libevent-usersin the body.
>


Thank you for input,
make me reread some doc:
event assign say:

Note that it is NOT safe to call this function on an event that is active
or pending. Doing so WILL corrupt internal data structures in Libevent, and
lead to strange, hard-to-diagnose bugs. You _can_ use event_assign to
change an existing event, but only if it is not active or pending!

and i do not know why i was reassigning the same event.

works much better now i ASSIGN once and then del /add :-)

love libevent :-)

-- 
-
() ascii ribbon campaign - against html e-mail
/\


[Libevent-users] Simple question about multithreading SSL bufferevents.

2013-03-26 Thread John
Hello all,

I am having significant issues with (near immediate) deadlock when trying to 
send data out a single openssl bufferevent from two separate threads. The 
individual threads themselves send complete messages with each write. This 
should present no real problem from a synchronization perspective. In fact, the 
code works flawlessly when using ordinary bufferevents (not ssl bufferevents).

Are there any known issues with writing to a single openssl bufferevent from 
multiple threads concurrently? Should I have the expectation of this working, 
presuming my code is written correctly? I believe I have initialized libevent 
and openssl correctly for multithreaded execution.

Thanks,
-John


More info, for those interested:

My code fails in the same manner on both OSX and Linux. Both are built with 
multithreaded libevent/openssl support. (Verified at build time, not 
programatically. What's a good way to test openssl itself to see if it was 
built thread safe? I have verified openssl is calling my locking routines with 
a variety of lock indexes and the like)

I am running:
SSL version: OpenSSL 1.0.1c 10 May 2012
Libevent version: 2.0.21-stable

I have done the following:

1. Initialized openssl per Viega/Messier/Chandra, "Network Security with 
OpenSSL". (Before using any SSL.)
2. Initialized libevent with evthread_use_pthreads() (Before using any 
libevent- and verified result)
3. Use option BEV_OPT_THREADSAFE on the bufferevents being created.

And the following, none of which should be required, and none of which helped:

1. Used a global mutex surrounding all calls to libevent.
2. called evbuffer_enable_locking() on both evbuffers associated with the 
bufferevent.

And verified, for sanity:

1. The shared libraries I am loading are the libraries I expect the system to 
use.


My server is simply openssl acting as server, using some simple genetated 
certificates.

I would be happy to share my test code- but it is ~300ish lines due to 
(primarily) openssl and thread initialization.

***
To unsubscribe, send an e-mail to majord...@freehaven.net with
unsubscribe libevent-usersin the body.


[Libevent-users] bufferevent read high watermark and missing error/event callback

2013-03-26 Thread Mina Naguib

Hi

I've run into an issue and I'm wondering if it's expected behavior or not.

If a bufferevent with a configured read-high-watermark actually reaches the 
watermark, the TCP disconnect on the underlying socket is not reported.  I've 
observed this on Mac OS X (kevent) as well as linux 3.5 (epoll), using libevent 
2.0.21

Here's a simple example.  Error checking omitted for brevity:  
https://gist.github.com/minaguib/5250939

To reproduce, compile and run the server, which will listen on port 5001.

Do a simple test which does not exceed the read high watermark:
$ echo "1" | nc localhost 5001
The server prints:
New client
Got data from client - ignoring it
Client disconnected

Next, do a simple test which exceeds the read high watermark:
$ echo "hello world" | nc localhost 5001
The server prints:
New client
Got data from client - ignoring it

Note that even though netcat has died, and the client->server FIN packet has 
been sent and ACKnowledged (verified with tcpdump), the 
handle_client_buffer_evt callback was never invoked.

Is it a requirement that input is fully drained so that libevent can observe 
the underlying socket's closure ?  Perhaps I've wrongly assumed that 
event/error notifications are out-of-band when they're not.

FWIW this is what I see with strace on linux when I write "hello world" from 
the client then the client closes:

{{EPOLLIN, {u32=8, u64=8}}}, 32, -1) = 1
ioctl(8, FIONREAD, [13])= 0
readv(8, [{"hell", 4}], 1)  = 4
epoll_ctl(3, EPOLL_CTL_DEL, 8, {EPOLLIN, {u32=8, u64=8}}) = 0
write(1, "Got data from client - ignoring "..., 35Got data from client 
- ignoring it
) = 35
epoll_wait(3,







***
To unsubscribe, send an e-mail to majord...@freehaven.net with
unsubscribe libevent-usersin the body.


Re: [Libevent-users] bufferevent read high watermark and missing error/event callback

2013-03-26 Thread Nick Mathewson
On Tue, Mar 26, 2013 at 10:31 PM, Mina Naguib
 wrote:
>
> Hi
>
> I've run into an issue and I'm wondering if it's expected behavior or not.
>
> If a bufferevent with a configured read-high-watermark actually reaches the 
> watermark, the TCP disconnect on the underlying socket is not reported.  I've 
> observed this on Mac OS X (kevent) as well as linux 3.5 (epoll), using 
> libevent 2.0.21
>

I don't believe there's a way that works across all backends to learn
that a socket has become closed when you're not listening for reads on
it and you're not trying to write on it.  Is this implementable?
***
To unsubscribe, send an e-mail to majord...@freehaven.net with
unsubscribe libevent-usersin the body.