[AGENT++] SNMP++ Slow socket closing and SNMP_CLASS_TL_IN_USE

Stoyan Haralampiev tony at gyuvetch.bg
Thu Jan 18 17:45:20 CET 2007


Hi,

>-------- Оригинално писмо --------
>От: Jochen Katz  
>Относно: Re: [AGENT++] SNMP++ Slow socket closing and SNMP_CLASS_TL_IN_USE
>До: agentpp at agentpp.org
>Изпратено на: Четвъртък, 2007, Януари 18 00:11:05 GMT+02:00
>----------------------------------
>
>Hi,
>
>> This time it's about Snmp::notify_register() returning
>> SNMP_CLASS_TL_IN_USE when called several consequtive times. I tested
>> it both under Win32 and Linux and it happens only under Linux.
>
>just to be sure: you call notify_register() right after
>notify_unregister() and then notify_register() returns SNMP_CLASS_TL_IN_USE.
>

Actually I tried with calling it and without calling it prior to notify_register() and in both cases I get the error.
The reason seems to be that both
notify_register() and notify_unregister()
call:

eventListHolder->notifyEventList()->DeleteEntry(this);

which closes the sockets in use.
So calling unregister first should make no difference.

>> As far as I understand the socket does not get closed during the call
>> to close() and when bind is attempted again in a very short time
>> (several mls) the address/port seem to already be in use.
>> 
>> It seems that using SO_REUSEADDR (or maybe SO_LINGER but this could
>> be more complex because of getting the right timeout value) would
>> solve the problem.
>
>Until now, I never heard of UDP sockets having a TIME_WAIT phase like
>TCP... If you're right the following code in
>CNotifyEventQueue::AddEntry() should solve it:
>
I could be wrong about this one but the docs that I found claim that SO_REUSEADDR causes a socket to reuse the addr/port already in use by another socket and
it may be
used by servers that are
started immediately after
getting stopped
(just like in our case). It could be only for TCP - I am not sure.

> int ii = 1;
> if (setsockopt(m_notify_fds[i], SOL_SOCKET, SO_REUSEADDR,
> (const char *)&ii,
> sizeof(ii)) < 0 ) {
> LOG_BEGIN(ERROR_LOG | 1);
> LOG("setsockopt failed, but it is ignored (errno)");
> LOG(errno);
> LOG_END;
> }
>
>Could you test this and report if it works and solves your problem?
>
I'll try to test this one to be sure.

Anyway I noticed the following:
The problem may be reproduced on my machine only when notify_register is called multiple times after(!) start_poll_thread has been called.
If stop_poll_thread() is called before calling notify_register() the problem does not occur.
If notify_unregister() is called, then a
sleep
(500 ms interval works for me)
gets issued and then notify_register() is called
- we
are again successful.

>Regards,
> Jochen
>
>_______________________________________________
>AGENTPP mailing list
>AGENTPP at agentpp.org
>http://lists.agentpp.org/mailman/listinfo/agentpp
> 


Best regards,
Tony 

-----------------------------------------------------------------
Заложете на късмета си със Спортингбет!


More information about the AGENTPP mailing list