Jonathan Tan <jonathantanmy@xxxxxxxxxx> writes: >> Jonathan Tan <jonathantanmy@xxxxxxxxxx> writes: >> >> > @@ -126,6 +129,12 @@ static int read_pack_objects_stdout(int outfd, struct output_state *os) >> > } >> > os->used += readsz; >> > >> > + if (!os->packfile_started) { >> > + os->packfile_started = 1; >> > + if (use_protocol_v2) >> > + packet_write_fmt(1, "packfile\n"); >> >> If we fix this function so that the only byte in the buffer is held >> back without emitted when os->used == 1 as I alluded to, this may >> have to be done a bit later, as with such a change, it is no longer >> guaranteed that send_client_data() will be called after this point. > > I'm not sure what you mean about there being no guarantee that > send_client_data() is not called - in create_pack_file(), there is an > "if (output_state.used > 0)" line (previously "if (0 <= buffered)") that > outputs anything remaining. I was referring to this part of the review on the previous step, which you may not yet have read. OK, this corresponds to the "*cp++ = buffered" in the original just before xread(). > + os->used = 1; > + } else { > + send_client_data(1, os->buffer, os->used); > + os->used = 0; I am not sure if the code is correct when os->used happens to be 1 (shouldn't we hold the byte, skip the call to send_client_data(), and go back to poll() to expect more data?), but this is a faithful code movement and rewrite of the original. The point of this logic is to make sure we always hold back some bytes and do not feed *all* the bytes to the other side by calling "send-client-data" until we made sure the upstream of what we are relaying (pack-objects?) successfully exited, but it looks to me that the "else" clause above ends up flushing everything when os->used is 1, which goes against the whole purpose of the code. And the "fix" I was alluding to was to update that "else" clause to make it a no-op that keeps os->used non-zero, which would not call send-client-data. When that fix happens, the part that early in the function this patch added "now we know we will call send-client-data, so let's say 'here comes packdata' unless we have already said that" is making the decision too early. Depending on the value of os->used when we enter the code and the number of bytes xread() reads from the upstream, we might not call send-client-data yet (namely, when we have no buffered data and we happened to get only one byte). > ... it might be > better if the server can send sideband throughout the whole response - > perhaps that should be investigated first. Yup. It just looked quite crazy, and it is even more crazy to buffer keepalives ;-)