Re: [Libevent-users] Must delete events before closing the socket handle

2009-09-17 Thread Nick Mathewson
On Fri, Sep 18, 2009 at 11:09:52AM +0800, Adrian Chadd wrote:
> On Thu, Sep 17, 2009, Nick Mathewson wrote:
> 
> > > Nick, is this actually documented anywhere?
> > 
> > Not that I recall, and  it really ought to be.  Anybody want to write the
> > documentation patch?
> 
> I've been threatening to do this for ages. I may as well start now.
> 
> Is there a project wiki or something somewhere where I can start
> braindumping "clue" into?

Right now most of the clue is in the reference book thing I've started
writing.  The source for it is here, in Git:
 git://git.torproject.org/~nickm/git/lebook.git

I'm glad to apply patches or pull contributions from other people's
repositories.

There's no wiki; if somebody knows a good wiki host that we should
use, I'd be glad to set one up for non-book things, though I'd like to
concentrate as much clue in the book as possible.

Also, as a heads-up: We'll probably be moving the mailing list to some
other host soon, due to monkeymail's general unreliability.  Currently
sourceforge seems likeliest.  The likeliest time for this, assuming we
don't flake out, is next week once Niels is back home.

yrs,
-- 
Nick




___
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users


Re: [Libevent-users] Must delete events before closing the socket handle

2009-09-17 Thread William Ahern
On Thu, Sep 17, 2009 at 07:51:58PM -0700, Gilad Benjamini wrote:
> I just resolved a similar issue today, where I needed to close a file
> descriptor AFTER deleting an event.
> 
> My symptoms, though, were different.
> 
> What underlying mechanism is your libevent using ?
> 
> In my case it is epoll. With select or poll my scenario had no problems, in
> spite of the wrong order.
> 

Few people do it, but these--and other--errors would be easier to catch if
people checked the return value of event_del().

I often use assert(0 == event_del()), because if event_del() is failing then
in all likelihood I have a bug in my code (the alternative being a bug in
libevent, or a kernel bug). 'Tis better to have QA screaming at you, or a
few hundred upset customers, than to roll out a buggy app to
tens-of-thousands of customers and watch tech support disintegrate as you
struggle to locate the source of the bug, assuming you can even get a trace.
(This is also why setting NDEBUG for the "production" build is usually
counter-productive.)
___
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users


Re: [Libevent-users] Must delete events before closing the socket handle

2009-09-17 Thread Clint Webb
I forgot to mention that I am using libevent-2.02alpha.
I think it definately makes sence to free the event before closing the
handle, but it just didn't occur to me before.


On Fri, Sep 18, 2009 at 10:57 AM, Adrian Chadd wrote:

> Well, the order of which you can do this depends on what the underlying OS
> will
> "do for you".
>
> I'd suggest sticking to "delete event, close socket" usage. Anything else
> isn't portable.
>
> Nick, is this actually documented anywhere?
>
>
>
> Adrian
>
> On Thu, Sep 17, 2009, Gilad Benjamini wrote:
> > I just resolved a similar issue today, where I needed to close a file
> > descriptor AFTER deleting an event.
> >
> > My symptoms, though, were different.
> >
> > What underlying mechanism is your libevent using ?
> >
> > In my case it is epoll. With select or poll my scenario had no problems,
> in
> > spite of the wrong order.
> >
> >
> >
> > From: libevent-users-boun...@monkey.org
> > [mailto:libevent-users-boun...@monkey.org] On Behalf Of Clint Webb
> > Sent: Thursday, September 17, 2009 7:46 PM
> > To: libevent-users@monkey.org
> > Subject: [Libevent-users] Must delete events before closing the socket
> > handle
> >
> >
> >
> > Hello everyone,
> >
> >
> >
> > After spending over a week debugging a project I am working on, I have
> > discovered that you must delete any persistent events BEFORE you close
> the
> > socket handle.
> >
> > Just letting other people know who might not have noticed it before.
> >
> >
> >
> > The symptom will be that the next time the same socket handle is
> assigned,
> > events will not fire when data arrives on the socket.   In some cases I
> was
> > getting segfaults.
> >
> >
> > I've attached some code that will echo what it receives.   It can be used
> to
> > demonstrate what happens.
> >
> >
> >
> >
> >
> >
> > --
> > "Be excellent to each other"
> >
>
> > ___
> > Libevent-users mailing list
> > Libevent-users@monkey.org
> > http://monkeymail.org/mailman/listinfo/libevent-users
>
>
> --
> - Xenion - http://www.xenion.com.au/ - VPS Hosting - Commercial Squid
> Support -
> - $25/pm entry-level VPSes w/ capped bandwidth charges available in WA -
>



-- 
"Be excellent to each other"
___
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users


Re: [Libevent-users] Must delete events before closing the socket handle

2009-09-17 Thread Adrian Chadd
On Thu, Sep 17, 2009, Nick Mathewson wrote:

> > Nick, is this actually documented anywhere?
> 
> Not that I recall, and  it really ought to be.  Anybody want to write the
> documentation patch?

I've been threatening to do this for ages. I may as well start now.

Is there a project wiki or something somewhere where I can start braindumping 
"clue"
into?


Adrian

___
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users


Re: [Libevent-users] Must delete events before closing the socket handle

2009-09-17 Thread Nick Mathewson
On Fri, Sep 18, 2009 at 10:57:25AM +0800, Adrian Chadd wrote:
> Well, the order of which you can do this depends on what the underlying OS 
> will
> "do for you".
> 
> I'd suggest sticking to "delete event, close socket" usage. Anything else
> isn't portable.
> 
> Nick, is this actually documented anywhere?

Not that I recall, and  it really ought to be.  Anybody want to write the
documentation patch?

-- 
Nick
___
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users


Re: [Libevent-users] Must delete events before closing the socket handle

2009-09-17 Thread Adrian Chadd
Well, the order of which you can do this depends on what the underlying OS will
"do for you".

I'd suggest sticking to "delete event, close socket" usage. Anything else
isn't portable.

Nick, is this actually documented anywhere?



Adrian

On Thu, Sep 17, 2009, Gilad Benjamini wrote:
> I just resolved a similar issue today, where I needed to close a file
> descriptor AFTER deleting an event.
> 
> My symptoms, though, were different.
> 
> What underlying mechanism is your libevent using ?
> 
> In my case it is epoll. With select or poll my scenario had no problems, in
> spite of the wrong order.
> 
>  
> 
> From: libevent-users-boun...@monkey.org
> [mailto:libevent-users-boun...@monkey.org] On Behalf Of Clint Webb
> Sent: Thursday, September 17, 2009 7:46 PM
> To: libevent-users@monkey.org
> Subject: [Libevent-users] Must delete events before closing the socket
> handle
> 
>  
> 
> Hello everyone, 
> 
>  
> 
> After spending over a week debugging a project I am working on, I have
> discovered that you must delete any persistent events BEFORE you close the
> socket handle.
> 
> Just letting other people know who might not have noticed it before.
> 
>  
> 
> The symptom will be that the next time the same socket handle is assigned,
> events will not fire when data arrives on the socket.   In some cases I was
> getting segfaults.
> 
> 
> I've attached some code that will echo what it receives.   It can be used to
> demonstrate what happens.
> 
>  
> 
>  
> 
> 
> -- 
> "Be excellent to each other"
> 

> ___
> Libevent-users mailing list
> Libevent-users@monkey.org
> http://monkeymail.org/mailman/listinfo/libevent-users


-- 
- Xenion - http://www.xenion.com.au/ - VPS Hosting - Commercial Squid Support -
- $25/pm entry-level VPSes w/ capped bandwidth charges available in WA -
___
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users


Re: [Libevent-users] Must delete events before closing the socket handle

2009-09-17 Thread Gilad Benjamini
I just resolved a similar issue today, where I needed to close a file
descriptor AFTER deleting an event.

My symptoms, though, were different.

What underlying mechanism is your libevent using ?

In my case it is epoll. With select or poll my scenario had no problems, in
spite of the wrong order.

 

From: libevent-users-boun...@monkey.org
[mailto:libevent-users-boun...@monkey.org] On Behalf Of Clint Webb
Sent: Thursday, September 17, 2009 7:46 PM
To: libevent-users@monkey.org
Subject: [Libevent-users] Must delete events before closing the socket
handle

 

Hello everyone, 

 

After spending over a week debugging a project I am working on, I have
discovered that you must delete any persistent events BEFORE you close the
socket handle.

Just letting other people know who might not have noticed it before.

 

The symptom will be that the next time the same socket handle is assigned,
events will not fire when data arrives on the socket.   In some cases I was
getting segfaults.


I've attached some code that will echo what it receives.   It can be used to
demonstrate what happens.

 

 


-- 
"Be excellent to each other"

___
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users


Re: [Libevent-users] Infinite loop in event_process_active()

2009-09-17 Thread Nick Mathewson
On Thu, Sep 17, 2009 at 02:56:59PM +0200, nicolas dumont wrote:
> Hi,
> 
> I'm using events in 1.4.12-stable.

 [...]
> Finnaly, to prevent to go in the infinite loop ,
> do I have to run event_del(&ev) each time before using event_set(&ev) ?

This is exactly so.  You can't call event_set or event_assign on an
event while it is added.

Unfortunately, because event_set works on uninitialized memory, there
is no way for it to check whether it's looking at an added event, or a
random chunk of memory that happens to have bits set in the right
place.

-- 
Nick
___
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users


[Libevent-users] Infinite loop in event_process_active()

2009-09-17 Thread nicolas dumont

Hi,

I'm using events in 1.4.12-stable.

Sometimes, my daemon, which uses event_base_loop()
goes in an infinite loop ( verbose traces below ).

This infinite loop is inside function event_process_active() which
calls event_del() with ev_flags=0x80 ( =EVLIST_INIT)
This flags is not managed by event_del(), then the ev is never deleted
from the queue, then the loop "for" retries again and again.

static void event_process_active(struct event_base *base)
{
...
 for (ev = TAILQ_FIRST(activeq); ev; ev = TAILQ_FIRST(activeq)) {
 if (ev->ev_events & EV_PERSIST)
 event_queue_remove(base, ev, EVLIST_ACTIVE);
 else
 event_del(ev);
...
   }
}


[2009-08-26 17:12:29] ev  : event_add: event: 0xb13a7e0, EV_READ
call 0x280b789c
[2009-08-26 17:12:29] ev  : kq_insert: fd 43 EVFILT_READ
[2009-08-26 17:12:29] ev  : event_queue_insert queue=0x2  ev_flags=0x1082
[2009-08-26 17:12:29] ev  : event_process_active: call event_del
[2009-08-26 17:12:29] ev  : event_del: 0xb13e6a0, callback 0x280b7dd4,
ev_flags 0x1082 ev_events 0x2
[2009-08-26 17:12:29] ev  : event_queue_remove queue=0x2  ev_flags=0x1080
[2009-08-26 17:12:29] ev  : kq_insert: fd 74 EVFILT_READ (del)
[2009-08-26 17:12:29] ev  : event_process_active: call event_del
[2009-08-26 17:12:29] ev  : event_del: 0xb13e6a0, callback 0x280b7dd4,
ev_flags 0x80 ev_events 0x2
[2009-08-26 17:12:29] ev  : event_process_active: call event_del
[2009-08-26 17:12:29] ev  : event_del: 0xb13e6a0, callback 0x280b7dd4,
ev_flags 0x80 ev_events 0x2
[2009-08-26 17:12:29] ev  : event_process_active: call event_del
[2009-08-26 17:12:29] ev  : event_del: 0xb13e6a0, callback 0x280b7dd4,
ev_flags 0x80 ev_events 0x2
[2009-08-26 17:12:29] ev  : event_process_active: call event_del
[2009-08-26 17:12:29] ev  : event_del: 0xb13e6a0, callback 0x280b7dd4,
ev_flags 0x80 ev_events 0x2
[2009-08-26 17:12:29] ev  : event_process_active: call event_del
[2009-08-26 17:12:29] ev  : event_del: 0xb13e6a0, callback 0x280b7dd4,
ev_flags 0x80 ev_events 0x2
.

...
..
.

After investigating my code, I found that I call in this order :

event_set(&ev, EV_READ,callback_one);
event_add(&ev);

and later :
event_set(&ev, EV_READ,callback_two);

The pb is that the second event_set which is called to set another 
callback resets the ev->flags with EVLIST_INIT

After that I fall into the infinite loop describe behind.

So, even if I'm doing something wrong with the usage of the API, it 
should not go in an infinite loop.


Finnaly, to prevent to go in the infinite loop ,
do I have to run event_del(&ev) each time before using event_set(&ev) ?

Thank's a lot for your answer.

Nicolas.

--
Nicolas Dumont
System development engineer

NETASQ - We secure IT
3 rue Archimede
59650 Villeneuve d'Ascq
France
Tel :  +33 (0)3.20.61.90.44
Fax :  +33 (0)3.20.61.97.48 



smime.p7s
Description: S/MIME Cryptographic Signature
___
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users