Skip to content

Commit 16fb285

Browse files
authored
fix: race condition with interruptibles (#566)
* fix: race condition with interruptibles * fix: make attr_reader private
1 parent 37ae2ce commit 16fb285

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/solid_queue/processes/base.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module SolidQueue
44
module Processes
55
class Base
66
include Callbacks # Defines callbacks needed by other concerns
7-
include AppExecutor, Registrable, Interruptible, Procline
7+
include AppExecutor, Registrable, Procline
8+
prepend Interruptible
89

910
attr_reader :name
1011

lib/solid_queue/processes/interruptible.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22

33
module SolidQueue::Processes
44
module Interruptible
5+
def initialize(...)
6+
super
7+
@self_pipe = create_self_pipe
8+
end
9+
510
def wake_up
611
interrupt
712
end
813

914
private
1015
SELF_PIPE_BLOCK_SIZE = 11
1116

17+
attr_reader :self_pipe
18+
1219
def interrupt
1320
self_pipe[:writer].write_nonblock(".")
1421
rescue Errno::EAGAIN, Errno::EINTR
@@ -25,10 +32,6 @@ def interruptible_sleep(time)
2532
end
2633

2734
# Self-pipe for signal-handling (http://cr.yp.to/docs/selfpipe.html)
28-
def self_pipe
29-
@self_pipe ||= create_self_pipe
30-
end
31-
3235
def create_self_pipe
3336
reader, writer = IO.pipe
3437
{ reader: reader, writer: writer }

0 commit comments

Comments
 (0)