Repository navigation
Commit de622e4
committed
fix(responses): verify the snapshot on disk before skipping a write
Skipping a byte-identical rewrite is the right fix for the amplification,
but the cached digest describes what this process last wrote, which is
not the same claim as what is on disk now. A second proxy sharing the
home, or anything that rewrites the file in place, leaves the digest
describing bytes that are gone.
That matters more than it sounds. Before the skip existed, every flush
rewrote the file and so repaired external damage silently. Skipping on
the digest alone turns a self-healing snapshot into a permanently corrupt
one, and nothing notices until the next restart fails to load the
continuation state. Replacing the file with different bytes of the same
length reproduces it: the digest still matches, the file still exists,
and the flush declines to repair.
The skip now verifies identity against the file itself. The cached digest
is keyed to the resolved write target, so a config-dir change or a
retargeted symlink is a miss rather than a false match, and the contents
are compared byte-for-byte before declining to write. Size is checked
first so the common mismatch costs a stat, any read failure answers "no"
and the caller rewrites, and the read only happens when the digest
already agreed. The amplification being fixed is the repeated 24 MiB
atomic replace, not the read that avoids it.
This also removes the need to trust Bun.hash for correctness. It stays a
cheap first filter, but a collision can no longer produce a false skip.
Tests: same-length external replacement must be rewritten, proven by
reverting only the disk check. The docs line claiming graceful shutdown
"always flushes" is corrected too — the flush is a disk write and can
fail like any other, and writeBoundedSnapshot swallows that into a
"failed" outcome the lifecycle warning cannot see.
124 pass across write-amplification and responses-state. tsc clean.1 parent fec2957 commit de622e4
3 files changed
Lines changed: 113 additions & 7 deletions
File tree
- docs-site/src/content/docs/troubleshooting
- src/responses
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | | - | |
68 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
104 | 125 | | |
105 | 126 | | |
106 | 127 | | |
| |||
805 | 826 | | |
806 | 827 | | |
807 | 828 | | |
808 | | - | |
809 | | - | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
810 | 841 | | |
811 | 842 | | |
812 | 843 | | |
813 | | - | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
814 | 847 | | |
815 | 848 | | |
816 | 849 | | |
817 | 850 | | |
818 | 851 | | |
819 | 852 | | |
| 853 | + | |
820 | 854 | | |
821 | 855 | | |
822 | 856 | | |
| |||
1462 | 1496 | | |
1463 | 1497 | | |
1464 | 1498 | | |
| 1499 | + | |
1465 | 1500 | | |
1466 | 1501 | | |
1467 | 1502 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
111 | 136 | | |
112 | 137 | | |
113 | 138 | | |
| |||
133 | 158 | | |
134 | 159 | | |
135 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
136 | 205 | | |
137 | 206 | | |
138 | 207 | | |
| |||
0 commit comments