Commit d425d96
committed
Batch HTTP/2 receive-window refills
Previously `refill_client_windows/3` sent a WINDOW_UPDATE on both the
connection and the stream after every DATA frame, with the increment
set to the frame's byte size. That kept the advertised window pinned
at its peak but tied outbound WINDOW_UPDATE traffic one-to-one with
inbound DATA frames.
An adversarial server can exploit that ratio. By sending many small
DATA frames — in the limit, one byte of body per frame — it can force
the client to emit one 13-byte WINDOW_UPDATE per frame. At high frame
rates that's a small but real client-side amplification: a flood of
outbound control frames driven entirely by the peer.
This change gates refills on a threshold. The client tracks the
current remaining window for the connection and each stream and only
sends a WINDOW_UPDATE once that remaining drops to
`:receive_window_update_threshold` bytes. The update then tops the
window straight back up to its configured peak. One frame per
`receive_window_size - receive_window_update_threshold` bytes
consumed, not per DATA frame. The default threshold is 160_000 bytes
— roughly 10× the default 16 KB max frame size, leaving the server a
safety margin before the window would starve it.
Behaviour-wise:
* With the 4 MB / 16 MB default windows, the client sends roughly
one stream-level WINDOW_UPDATE per ~3.84 MB consumed (previously
~250 per 4 MB), and one connection-level update per ~15.84 MB
(previously ~1000 per 16 MB).
* Callers that explicitly set the stream or connection window down
to the 65_535 spec minimum get the old behaviour — one refill per
frame — because remaining is always below the default 160_000
threshold.
The threshold is tunable via the new `:receive_window_update_threshold`
option to `Mint.HTTP.connect/4`.1 parent 3aced03 commit d425d96
3 files changed
Lines changed: 197 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
246 | 252 | | |
247 | 253 | | |
248 | 254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
150 | 156 | | |
151 | 157 | | |
152 | 158 | | |
| |||
189 | 195 | | |
190 | 196 | | |
191 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
192 | 207 | | |
193 | 208 | | |
194 | 209 | | |
| |||
896 | 911 | | |
897 | 912 | | |
898 | 913 | | |
899 | | - | |
| 914 | + | |
| 915 | + | |
900 | 916 | | |
901 | 917 | | |
902 | 918 | | |
| |||
908 | 924 | | |
909 | 925 | | |
910 | 926 | | |
911 | | - | |
| 927 | + | |
| 928 | + | |
912 | 929 | | |
913 | 930 | | |
914 | 931 | | |
| |||
1104 | 1121 | | |
1105 | 1122 | | |
1106 | 1123 | | |
1107 | | - | |
1108 | | - | |
1109 | | - | |
1110 | | - | |
| 1124 | + | |
1111 | 1125 | | |
1112 | | - | |
| 1126 | + | |
| 1127 | + | |
1113 | 1128 | | |
1114 | 1129 | | |
1115 | 1130 | | |
| |||
1144 | 1159 | | |
1145 | 1160 | | |
1146 | 1161 | | |
1147 | | - | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
1148 | 1165 | | |
1149 | 1166 | | |
1150 | 1167 | | |
| |||
1182 | 1199 | | |
1183 | 1200 | | |
1184 | 1201 | | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
1185 | 1210 | | |
1186 | 1211 | | |
1187 | 1212 | | |
| |||
1259 | 1284 | | |
1260 | 1285 | | |
1261 | 1286 | | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
1262 | 1290 | | |
1263 | 1291 | | |
1264 | 1292 | | |
| |||
1753 | 1781 | | |
1754 | 1782 | | |
1755 | 1783 | | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
1756 | 1792 | | |
1757 | | - | |
1758 | | - | |
| 1793 | + | |
1759 | 1794 | | |
1760 | | - | |
1761 | | - | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
| 1807 | + | |
| 1808 | + | |
| 1809 | + | |
| 1810 | + | |
| 1811 | + | |
1762 | 1812 | | |
1763 | 1813 | | |
1764 | 1814 | | |
1765 | 1815 | | |
1766 | 1816 | | |
| 1817 | + | |
| 1818 | + | |
| 1819 | + | |
| 1820 | + | |
| 1821 | + | |
| 1822 | + | |
| 1823 | + | |
| 1824 | + | |
| 1825 | + | |
| 1826 | + | |
| 1827 | + | |
| 1828 | + | |
| 1829 | + | |
| 1830 | + | |
| 1831 | + | |
| 1832 | + | |
| 1833 | + | |
| 1834 | + | |
| 1835 | + | |
| 1836 | + | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + | |
| 1841 | + | |
| 1842 | + | |
| 1843 | + | |
| 1844 | + | |
| 1845 | + | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
1767 | 1857 | | |
1768 | 1858 | | |
1769 | 1859 | | |
| |||
2108 | 2198 | | |
2109 | 2199 | | |
2110 | 2200 | | |
| 2201 | + | |
| 2202 | + | |
2111 | 2203 | | |
2112 | 2204 | | |
2113 | 2205 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
| 149 | + | |
148 | 150 | | |
149 | 151 | | |
150 | 152 | | |
| |||
157 | 159 | | |
158 | 160 | | |
159 | 161 | | |
| 162 | + | |
160 | 163 | | |
161 | 164 | | |
162 | 165 | | |
163 | 166 | | |
| 167 | + | |
164 | 168 | | |
165 | 169 | | |
166 | 170 | | |
| |||
1874 | 1878 | | |
1875 | 1879 | | |
1876 | 1880 | | |
| 1881 | + | |
1877 | 1882 | | |
1878 | 1883 | | |
1879 | 1884 | | |
| |||
1884 | 1889 | | |
1885 | 1890 | | |
1886 | 1891 | | |
| 1892 | + | |
1887 | 1893 | | |
1888 | 1894 | | |
1889 | 1895 | | |
1890 | 1896 | | |
1891 | 1897 | | |
| 1898 | + | |
1892 | 1899 | | |
1893 | 1900 | | |
1894 | 1901 | | |
| |||
1897 | 1904 | | |
1898 | 1905 | | |
1899 | 1906 | | |
| 1907 | + | |
1900 | 1908 | | |
1901 | 1909 | | |
1902 | 1910 | | |
| |||
1910 | 1918 | | |
1911 | 1919 | | |
1912 | 1920 | | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
| 1944 | + | |
| 1945 | + | |
| 1946 | + | |
| 1947 | + | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
| 1966 | + | |
| 1967 | + | |
| 1968 | + | |
| 1969 | + | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + | |
| 1973 | + | |
| 1974 | + | |
| 1975 | + | |
| 1976 | + | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
1913 | 2000 | | |
1914 | 2001 | | |
1915 | 2002 | | |
| |||
0 commit comments