Skip to content

Commit

Permalink
Allow new states slowly even when queue full (fixes Axel Beckert lockup)
Browse files Browse the repository at this point in the history
  • Loading branch information
keithw committed Jan 15, 2013
1 parent e9c4184 commit 2dcef54
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/network/networktransport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Transport<MyState, RemoteState>::Transport( MyState &initial_state, RemoteState
: connection( desired_ip, desired_port ),
sender( &connection, initial_state ),
received_states( 1, TimestampedState<RemoteState>( timestamp(), 0, initial_remote ) ),
receiver_quench_timer( 0 ),
last_receiver_state( initial_remote ),
fragments(),
verbose( false )
Expand All @@ -58,6 +59,7 @@ Transport<MyState, RemoteState>::Transport( MyState &initial_state, RemoteState
: connection( key_str, ip, port ),
sender( &connection, initial_state ),
received_states( 1, TimestampedState<RemoteState>( timestamp(), 0, initial_remote ) ),
receiver_quench_timer( 0 ),
last_receiver_state( initial_remote ),
fragments(),
verbose( false )
Expand Down Expand Up @@ -116,11 +118,16 @@ void Transport<MyState, RemoteState>::recv( void )
process_throwaway_until( inst.throwaway_num() );

if ( received_states.size() > 1024 ) { /* limit on state queue */
if ( verbose ) {
fprintf( stderr, "[%u] Receiver queue full, discarding %d (malicious sender or long-unidirectional connectivity?)\n",
(unsigned int)(timestamp() % 100000), (int)inst.new_num() );
uint64_t now = timestamp();
if ( now < receiver_quench_timer ) { /* deny letting state grow further */
if ( verbose ) {
fprintf( stderr, "[%u] Receiver queue full, discarding %d (malicious sender or long-unidirectional connectivity?)\n",
(unsigned int)(timestamp() % 100000), (int)inst.new_num() );
}
return;
} else {
receiver_quench_timer = now + 15000;
}
return;
}

/* apply diff to reference state */
Expand Down
1 change: 1 addition & 0 deletions src/network/networktransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace Network {

/* simple receiver */
list< TimestampedState<RemoteState> > received_states;
uint64_t receiver_quench_timer;
RemoteState last_receiver_state; /* the state we were in when user last queried state */
FragmentAssembly fragments;
bool verbose;
Expand Down

0 comments on commit 2dcef54

Please sign in to comment.