diff --git a/dlls/ntdll/sync.c b/dlls/ntdll/sync.c
index 3e27d09d7eef6a538a3ac0399d0b058d31bd28bc..f759ce6e7a5a2f4c09b1dab152196f634d12dcef 100644
--- a/dlls/ntdll/sync.c
+++ b/dlls/ntdll/sync.c
@@ -807,7 +807,7 @@ static int wait_reply( void *cookie )
         ret = read( ntdll_get_thread_data()->wait_fd[0], &reply, sizeof(reply) );
         if (ret == sizeof(reply))
         {
-            if (!reply.cookie) break;  /* thread got killed */
+            if (!reply.cookie) abort_thread( reply.signaled );  /* thread got killed */
             if (wine_server_get_ptr(reply.cookie) == cookie) return reply.signaled;
             /* we stole another reply, wait for the real one */
             signaled = wait_reply( cookie );
@@ -826,8 +826,6 @@ static int wait_reply( void *cookie )
         if (errno == EINTR) continue;
         server_protocol_perror("wakeup read");
     }
-    /* the server closed the connection; time to die... */
-    abort_thread(0);
 }
 
 
diff --git a/server/thread.c b/server/thread.c
index f704473fc592f1851c228a142caebbe496b19472..f9a575eae13d4bd15ff620cac2074638524d45b5 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -986,7 +986,7 @@ void kill_thread( struct thread *thread, int violent_death )
     if (thread->wait)
     {
         while (thread->wait) end_wait( thread );
-        send_thread_wakeup( thread, 0, STATUS_PENDING );
+        send_thread_wakeup( thread, 0, thread->exit_code );
         /* if it is waiting on the socket, we don't need to send a SIGQUIT */
         violent_death = 0;
     }