@@ -134,18 +134,18 @@ def run
134
134
end
135
135
136
136
def with_env_vars ( env )
137
- old_env = ENV . to_hash
138
-
139
- # TODO move env-filtering
140
137
# Delete all env vars which are unchanged from before spring started
141
138
original_env . each { |k , v | ENV . delete k if ENV [ k ] == v }
142
139
140
+ changed_keys = env . keys - ENV . keys
143
141
# Load in the current env vars, except those which *were* changed when spring started
144
142
env . each { |k , v | ENV [ k ] ||= v }
145
143
146
144
yield
147
145
ensure
148
- ENV . replace ( old_env . to_hash )
146
+ changed_keys . each do |k |
147
+ original_env . has_key? ( k ) ? ENV [ k ] = original_env [ k ] : ENV . delete ( k )
148
+ end
149
149
end
150
150
151
151
def serve ( client )
@@ -157,6 +157,7 @@ def serve(client)
157
157
158
158
client_args , client_env = JSON . load ( client . read ( client . gets . to_i ) ) . values_at ( "args" , "env" )
159
159
160
+ @pid = nil
160
161
with_env_vars ( client_env ) do
161
162
preload unless preloaded?
162
163
command = Spring . command ( client_args . shift )
@@ -169,7 +170,7 @@ def serve(client)
169
170
ActionDispatch ::Reloader . prepare!
170
171
end
171
172
172
- pid = fork {
173
+ @ pid = fork {
173
174
IGNORE_SIGNALS . each { |sig | trap ( sig , "DEFAULT" ) }
174
175
trap ( "TERM" , "DEFAULT" )
175
176
@@ -197,20 +198,20 @@ def serve(client)
197
198
disconnect_database
198
199
reset_streams
199
200
200
- log "forked #{ pid } "
201
- manager . puts pid
201
+ log "forked #{ @ pid} "
202
+ manager . puts @ pid
202
203
203
- wait pid , streams , client
204
+ wait @ pid, streams , client
204
205
rescue Exception => e
205
206
log "exception: #{ e } "
206
- manager . puts unless pid
207
+ manager . puts unless @ pid
207
208
208
209
if streams && !e . is_a? ( SystemExit )
209
210
print_exception ( stderr , e )
210
211
streams . each ( &:close )
211
212
end
212
213
213
- client . puts ( 1 ) if pid
214
+ client . puts ( 1 ) if @ pid
214
215
client . close
215
216
end
216
217
0 commit comments