Skip to content

Commit 05d6b43

Browse files
committed
✅ Add a Mutex to FakeServer (for tests only)
While trying to track down the cause of #287 for @hsbt, I noticed that this is likely a race condition. While this can't be the cause of that issue (the failures come from tests that don't even use FakeServer), it seems like a good idea to fix anyway, and safe.
1 parent 004305e commit 05d6b43

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

test/net/imap/fake_server.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def initialize(...)
6161
@config = Configuration.new(...)
6262
@tcp_server = TCPServer.new(config.hostname, config.port)
6363
@connection = nil
64+
@mutex = Thread::Mutex.new
6465
end
6566

6667
def host; tcp_server.addr[2] end
@@ -84,9 +85,11 @@ def run
8485
# accepted and closed. This may change in the future. Call #shutdown
8586
# explicitly to ensure the server socket is unbound.
8687
def shutdown
87-
connection&.close
88-
commands&.close if connection&.commands&.closed?&.!
89-
tcp_server.close
88+
@mutex.synchronize do
89+
connection&.close
90+
commands&.close if connection&.commands&.closed?&.!
91+
tcp_server.close
92+
end
9093
end
9194

9295
# A Queue that contains every command the server has received.

0 commit comments

Comments
 (0)