Skip to content

Commit

Permalink
Handle not yet registered workers
Browse files Browse the repository at this point in the history
Fix: #57

I suspect it's a race condition caused by a workers being freshly
respawned but not yet registered.

In such case we don't have a socket to write into, we should
just wait.
  • Loading branch information
byroot committed Aug 3, 2023
1 parent 0290e18 commit 69f4d0b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/pitchfork/http_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,11 @@ def restart_outdated_workers
if workers_to_restart > 0
outdated_workers = @children.workers.select { |w| !w.exiting? && w.generation < @children.mold.generation }
outdated_workers.each do |worker|
logger.info("worker=#{worker.nr} pid=#{worker.pid} gen=#{worker.generation} restarting")
worker.soft_kill(:TERM)
if worker.soft_kill(:TERM)
logger.info("Sent SIGTERM to worker=#{worker.nr} pid=#{worker.pid} gen=#{worker.generation}")
else
logger.info("Failed to send SIGTERM to worker=#{worker.nr} pid=#{worker.pid} gen=#{worker.generation}")
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/pitchfork/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ def pipe=(socket)

def send_message_nonblock(message)
success = false
return false unless @master
begin
case @master.sendmsg_nonblock(message, exception: false)
when :wait_writable
Expand Down

0 comments on commit 69f4d0b

Please sign in to comment.