Skip to content

Commit

Permalink
Server: Drain eventSource before initiating server disconnects
Browse files Browse the repository at this point in the history
this avoids breaking custom disconnects due to a race condition.

closes #102
  • Loading branch information
dktapps committed Sep 20, 2021
1 parent eb01243 commit e49157d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/server/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ public function tickProcessor() : void{
*/
public function waitShutdown() : void{
$this->shutdown = true;

while($this->eventSource->process($this)){
//Ensure that any late messages are processed before we start initiating server disconnects, so that if the
//server implementation used a custom disconnect mechanism (e.g. a server transfer), we don't break it in
//race conditions.
}

foreach($this->sessions as $session){
$session->initiateDisconnect("server shutdown");
}
Expand Down

0 comments on commit e49157d

Please sign in to comment.