Commit 3a5aa87
committed
Optimize the lifecycle of async requests
Async HTTP request work by emitting a "Progress" object to a callback. This
object has a "done" flag which, when `true`, indicates that all data has been
emitting and no future "Progress" objects will be sent.
Callers like XHR buffer the response and wait for "done = true" to then process
the request.
The HTTP client relies on two important object pools: the connection and the
state (with all the buffers for reading/writing).
In its current implementation, the async flow does not release these pooled
objects until the final callback has returned. At best, this is inefficient:
we're keeping the connection and state objects checked out for longer than they
have to be. At worse, it can lead to a deadlock. If the calling code issues a
new request when done == true, we'll eventually run out of state objects in the
pool.
This commit now releases the state objects before emit the final "done" Progress
message. For this to work, this final message will always have null data and
an empty header object.1 parent f436744 commit 3a5aa87
2 files changed
+35
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
468 | 468 | | |
469 | 469 | | |
470 | 470 | | |
471 | | - | |
472 | 471 | | |
473 | 472 | | |
474 | 473 | | |
| |||
522 | 521 | | |
523 | 522 | | |
524 | 523 | | |
525 | | - | |
| 524 | + | |
526 | 525 | | |
527 | 526 | | |
528 | 527 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
828 | 828 | | |
829 | 829 | | |
830 | 830 | | |
| 831 | + | |
831 | 832 | | |
832 | 833 | | |
833 | 834 | | |
| |||
966 | 967 | | |
967 | 968 | | |
968 | 969 | | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
969 | 977 | | |
970 | 978 | | |
| 979 | + | |
971 | 980 | | |
972 | 981 | | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
973 | 996 | | |
974 | 997 | | |
| 998 | + | |
975 | 999 | | |
976 | 1000 | | |
977 | 1001 | | |
| |||
1116 | 1140 | | |
1117 | 1141 | | |
1118 | 1142 | | |
1119 | | - | |
| 1143 | + | |
1120 | 1144 | | |
1121 | | - | |
| 1145 | + | |
1122 | 1146 | | |
1123 | 1147 | | |
1124 | 1148 | | |
1125 | 1149 | | |
1126 | | - | |
| 1150 | + | |
1127 | 1151 | | |
1128 | 1152 | | |
1129 | 1153 | | |
1130 | | - | |
| 1154 | + | |
1131 | 1155 | | |
1132 | 1156 | | |
1133 | 1157 | | |
1134 | | - | |
| 1158 | + | |
1135 | 1159 | | |
1136 | 1160 | | |
1137 | 1161 | | |
| |||
3135 | 3159 | | |
3136 | 3160 | | |
3137 | 3161 | | |
3138 | | - | |
| 3162 | + | |
| 3163 | + | |
3139 | 3164 | | |
3140 | 3165 | | |
3141 | 3166 | | |
| |||
3144 | 3169 | | |
3145 | 3170 | | |
3146 | 3171 | | |
| 3172 | + | |
| 3173 | + | |
| 3174 | + | |
3147 | 3175 | | |
3148 | 3176 | | |
3149 | 3177 | | |
| |||
0 commit comments