Hi Vadim!

The prior patch will still be needed.
It worked in fact blocking the finalization.

The problem is that this blocking was too late because the "transport manager" finalization is the last thing that happens on API finalization chain.
In other words, the "transport manager" finalization is correctly blocked and waits the packet handling that is on the way, but before getting to the method that makes the "transport manager" finalization everything else was already finalized/deallocated (like, phapi, eXosip, etc). And it seems that "eXosip" finalization is the root of the problem.

First thing that came to my mind was an approach that we've used here with another library on similar condition.
We created a "pre-finalization" chain that is runned before the "finalization" one.

But, on this case, I think we can avoid a lot of changes just getting "transport manager" finalization method to the very beggining of "eXosip" termination routine, and the prior patch will make the rest of the job.

As you've suggested I'll make the change here and the necessary tests, getting back with the result as soon as possible.

Please let me know if you have any questions or disagreements.

Thanks and best regards,
Mauro.




Vadim Lebedev escreveu:
I've alredy integrated your patch..  
So if you want you can send and addtional one if your tests are conclusive.

Thanks
Vadim

Le 18 juin 09 à 21:35, Mauro Sergio Ferreira Brasil a écrit :

Hi Vadim!

I have experienced the same crash again, so the patch below wasn't enough.
Anyway, having a look on callstacks again, I noticed that "if" we can shift the line "transport_terminate();" up to the very beginning of "eXosip_quit" method, the problem will probably be avoided definitively.

Do you see any problems on this approach ?

Can I make this litle change and send you a new patch ?

Thanks and best regards,
Mauro.




Vadim Lebedev escreveu:
Applied

Thanks
Vadim
[email protected] wrote:
  
# HG changeset patch
# User [email protected]
# Date 1245179624 10800
# Node ID 081ee3dc01152ab3358293aa441c2a9110ef2e7a
# Parent  15be388684d5ac61ee2ef6f248b48eb3a1d4b96c
Added the critical section control on "transport_manager" avoiding the finalization while a packet is being handled by "transport_on_data_socket_event" method.

diff -r 15be388684d5 -r 081ee3dc0115 wifo/eXosip/transport_manager/transport_manager.c
--- a/wifo/eXosip/transport_manager/transport_manager.c	Tue Jun 16 19:55:04 2009 +0200
+++ b/wifo/eXosip/transport_manager/transport_manager.c	Tue Jun 16 16:13:44 2009 -0300
@@ -34,6 +34,8 @@
 static OWList * transport_data_socket_list = NULL ;
 static OWList * transport_listening_socket_list = NULL ;
 static pthread_mutex_t transport_socket_lists_mutex ;
+static pthread_mutex_t transport_termination_mutex ;
+static int is_terminating = 0;
 
 static void
 transport_on_data_socket_event
@@ -305,6 +307,17 @@
 		return -1 ;
 	}
 
+	if (pthread_mutex_init (& transport_termination_mutex, NULL))
+	{
+		pthread_mutex_destroy (& transport_socket_lists_mutex) ;
+		owlist_free (transport_listening_socket_list) ;
+		transport_listening_socket_list = NULL ;
+		owlist_free (transport_data_socket_list) ;
+		transport_data_socket_list = NULL ;
+		owsl_terminate () ;
+		return -1 ;
+	}
+
 	return 0 ;
 }
 
@@ -314,7 +327,18 @@
 {
 	int return_code = 0 ;
 
+	if ((return_code = pthread_mutex_lock (& transport_termination_mutex)) != 0)
+	{
+		//TODO: What ?
+		//return return_code;
+	}
+
+	is_terminating = 1;
+
+	pthread_mutex_unlock (& transport_termination_mutex);
+
 	return_code |= pthread_mutex_destroy (& transport_socket_lists_mutex) ;
+	return_code |= pthread_mutex_destroy (& transport_termination_mutex) ;
 
 	return_code |= owlist_free_all (transport_listening_socket_list, (void (*) (void *)) transport_socket_free) ;
 	transport_listening_socket_list = NULL ;
@@ -789,9 +813,21 @@
 	void * user_data
 )
 {
+	if (pthread_mutex_lock (& transport_termination_mutex))
+	{
+		return;
+	}
+
+	if (is_terminating)
+	{
+		pthread_mutex_unlock (& transport_termination_mutex);
+		return;
+	}
+
 	if (event & OWSL_EVENT_ERROR)
 	{
 		transport_socket_remove (socket, TRANSPORT_DATA) ;
+		pthread_mutex_unlock (& transport_termination_mutex);
 		return ;
 	}
 
@@ -799,6 +835,9 @@
 	{
 		transport_recv_callback (socket) ;
 	}
+
+	pthread_mutex_unlock (& transport_termination_mutex);
+
 	return ;
 }
 
@@ -810,6 +849,17 @@
 	void * user_data
 )
 {
+	if (pthread_mutex_lock (& transport_termination_mutex))
+	{
+		return;
+	}
+
+	if (is_terminating)
+	{
+		pthread_mutex_unlock (& transport_termination_mutex);
+		return;
+	}
+
 	if ((event & OWSL_EVENT_ERROR) != 0)
 	{
 		OWSLSocketType implementation = owsl_type_get (socket)  ;
@@ -819,6 +869,9 @@
 		{
 			transport_listen_error_callback (transport_protocol_get (implementation), bind_address) ;
 		}
+
+		pthread_mutex_unlock (& transport_termination_mutex);
+
 		return ;
 	}
 
@@ -829,7 +882,13 @@
 		{
 			transport_socket_add (new_socket, TRANSPORT_DATA) ;
 		}
+
+		pthread_mutex_unlock (& transport_termination_mutex);
+
 		return ;
 	}
+
+	pthread_mutex_unlock (& transport_termination_mutex);
+
 	return ;
 }


  
    



  

--
At.,                                                                                                                               
<CMMI_2.jpg> 
Technology and Quality on Information
Mauro Sérgio Ferreira Brasil
Coordenador de Projetos e Analista de Sistemas
+ [email protected]
: www.tqi.com.br
( + 55 (34)3291-1700
( + 55 (34)9971-2572


--
TQI - Technology and Quality on Information
At.,                                                                                                                               
 
Technology and Quality on Information
Mauro Sérgio Ferreira Brasil
Coordenador de Projetos e Analista de Sistemas
+ [email protected]
: www.tqi.com.br
( + 55 (34)3291-1700
( + 55 (34)9971-2572
_______________________________________________
QuteCom-dev mailing list
[email protected]
http://lists.qutecom.org/mailman/listinfo/qutecom-dev

Reply via email to