﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	field_blocks	field_dependson	field_seealso
195	Potential deadlock in recvfrom_core()	Jakub Jermář		"Consider the following snippet from socket_clinet.c::recvfrom_core():

{{{
fibril_rwlock_read_lock( & socket_globals.lock );
socket = sockets_find( socket_get_sockets(), socket_id );
if( ! socket ){
  fibril_rwlock_read_unlock( & socket_globals.lock );
  return ENOTSOCK;
}
fibril_mutex_lock( & socket->receive_lock );
++ socket->blocked;
while(( result = dyn_fifo_value( & socket->received )) <= 0 ){
  fibril_rwlock_read_unlock( & socket_globals.lock );
  fibril_condvar_wait( & socket->receive_signal, & socket->receive_lock );
  fibril_rwlock_read_lock( & socket_globals.lock );
}

}}}

The code uses two locking schemes for acquiring:

  A) socket_globals.lock
  B) socket->receive_lock

The first locking scheme (A -> B) is used before the code reaches the while loop; 

The second locking scheme (B -> A) is used after the wakeup from fibril_condvar_wait(), when B is attempted while still holding A.

Looks like B should be dropped after waking up from fibril_condvar_wait() and reacquired after A is locked one line below."	defect	closed	major	0.4.2	helenos/net/socket	mainline	fixed					
