@@ -854,7 +854,7 @@ static void switchToNewServer(dnbd3_uplink_t *uplink)
854854 */
855855static int sendReplicationRequest (dnbd3_uplink_t * uplink )
856856{
857- assert_uplink_thread ();
857+ assert_uplink_thread (); // Make sure we're not called from any other thread
858858 if ( uplink -> current .fd == -1 )
859859 return -1 ; // Should never be called in this state, consider send error
860860 if ( _backgroundReplication == BGR_DISABLED || uplink -> cacheFd == -1 )
@@ -1079,8 +1079,6 @@ static void handleReceive(dnbd3_uplink_t *uplink)
10791079 uplink -> image -> problem .queue = false;
10801080 }
10811081 mutex_unlock ( & uplink -> queueLock );
1082- // We don't remove the entry from the list here yet, to slightly increase the chance of other
1083- // clients attaching to this request while we write the data to disk
10841082 if ( entry -> to - entry -> from != inReply .size ) {
10851083 logadd ( LOG_WARNING , "Received payload length does not match! (is: %" PRIu32 ", expect: %u, %s:%d)" ,
10861084 inReply .size , (unsigned int )( entry -> to - entry -> from ), PIMG (uplink -> image ) );
@@ -1092,12 +1090,16 @@ static void handleReceive(dnbd3_uplink_t *uplink)
10921090 }
10931091 if ( likely ( uplink -> cacheFd != -1 ) ) {
10941092 tparams .jobs ++ ;
1095- threadpool_run ( & handleReceiveSaveToDisk , & tparams , NULL );
1093+ if ( !threadpool_run ( & handleReceiveSaveToDisk , & tparams , NULL ) ) {
1094+ handleReceiveSaveToDisk ( & tparams );
1095+ }
10961096 }
10971097 // 2) Send to any waiting clients
10981098 if ( entry -> clients != NULL ) {
10991099 tparams .jobs ++ ;
1100- threadpool_run ( & handleReceiveSendToClients , & tparams , NULL );
1100+ if ( !threadpool_run ( & handleReceiveSendToClients , & tparams , NULL ) ) {
1101+ handleReceiveSendToClients ( & tparams );
1102+ }
11011103 }
11021104 // 3) Trigger more background replication if applicable
11031105 if ( sendReplicationRequest ( uplink ) == -1 ) {
0 commit comments