Commit 694deb9
committed
Fix spawn_on_env vars leaking from server to app
Previously, variables specified by `spawn_on_env` would behave
inconsistently when the Spring server was created with one of those
variables set:
```
VAR_FROM_BOOT=before bin/rails ...
```
would cause future clients' apps to be booted with
`VAR_FROM_BOOT=before` set, even if the client is created without that
variable:
```
bin/rails ...
```
and additionally, Spring would hide that the app was _booted_ with that
var set by _unsetting_ it when the client attached to its app (making it
look like the correct ENV).
The issue was caused by how `spawn_on_env` was passed from client to
server to app:
- The client would slice `spawn_on_env` keys from its `ENV`, meaning
`bin/rails ...` would have an empty `spawn_on_env` hash.
- The server (which has `VAR_FROM_BOOT` set), forks an app with
`spawn_on_env` values set (none, because its an empty hash)
- The forked app inherits its parent's `ENV`, so it boots with
`VAR_FROM_BOOT` set
- The client gets a forked app process, and cleans up environment
variables from the server process
This is specifically an issue for `spawn_on_env` because the goal is to
have apps booted with different environments.
This commit fixes the issue by always passing all `Spring.spawn_on_env`
values from the client to the server (including `nil` ones) so that the
forked app will have those values cleared if necessary. `compact` is
added to the `SPRING_SPAWN_ENV` value because it is only used to display
the `spawn_on_env` values in `spring status` and showing all of the
`nil` values is noisy/unnecessary.1 parent 13ba7d3 commit 694deb9
File tree
3 files changed
+16
-2
lines changed- lib/spring
- client
- test/support
3 files changed
+16
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
258 | 260 | | |
259 | 261 | | |
260 | 262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
663 | 663 | | |
664 | 664 | | |
665 | 665 | | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
666 | 678 | | |
667 | 679 | | |
668 | 680 | | |
| |||
0 commit comments