Skip to content

Commit 4105015

Browse files
Fix reloading in Ruby 3.3
This commit ensures the application is restarted when a preloaded file is changed. This has been silently broken because the fallback behavior still results in the application being restarted, but only when the user next runs a command—hence the acceptance test still passing. The behavior of `BasicSocket#recv` changed in Ruby 3.3 [1] such that it now returns `nil` on a closed stream socket, instead of an empty string. When we call `#empty?` on `nil` the `NoMethodError` is swallowed by the failsafe thread and the application is not restarted. This commit fixes the issue by checking both `#nil?` and `#empty?` so it works with both old and new versions. It also updates the acceptance test to be more specific about what it considers a "reload" by asserting the relevant log line exists. [1]: ruby/ruby#6407
1 parent eefc42d commit 4105015

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Next Release
22

3+
* Fix reloading issue in Ruby 3.3.
4+
35
## 4.2.1
46

57
* Added `Spring.connect_timeout` and `Spring.boot_timeout` to allow to increase timeout for larger apps.

lib/spring/application_manager.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ def start_wait_thread(pid, child)
126126
# as if it does we're no longer interested in the child
127127
loop do
128128
IO.select([child])
129-
break if child.recv(1, Socket::MSG_PEEK).empty?
129+
peek = child.recv(1, Socket::MSG_PEEK)
130+
break if peek.nil? || peek.empty?
130131
sleep 0.01
131132
end
132133

test/support/acceptance_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def self.omg
189189
app.insert_into_test "Foo.omg"
190190

191191
app.await_reload
192-
assert_failure app.spring_test_command, stdout: "RuntimeError: omg"
192+
assert_failure app.spring_test_command, stdout: "RuntimeError: omg", log: /child \d+ shutdown/
193193
end
194194

195195
test "app gets reloaded even with a ton of boot output" do

0 commit comments

Comments
 (0)