You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Philip Martin <ph...@codematters.co.uk> on 2014/11/05 15:24:46 UTC
ra_serf infinite loop with mod_ssl and mod_deflate
Configure a server with both mod_ssl (HTTPS) and mod_deflate (HTTP
compression). Start a checkout and the kill the server. The client
goes into an infinite loop in libsvn_ra_serf/update.c:handle_fetch
(gdb) n
1147 svn_txdelta_window_t delta_window = { 0 };
(gdb) n
1151 status = serf_bucket_read(response, 8000, &data, &len);
(gdb) n
1152 if (SERF_BUCKET_READ_ERROR(status))
(gdb) n
1157 fetch_ctx->read_size += len;
(gdb) n
1159 if (fetch_ctx->aborted_read)
(gdb) n
1187 if (fetch_ctx->result_stream)
(gdb) n
1191 else if (len)
(gdb) n
1209 if (APR_STATUS_IS_EOF(status))
(gdb) n
1218 if (status)
(gdb) n
1220 }
(gdb) n
1147 svn_txdelta_window_t delta_window = { 0 };
I don't know if the bug is serf failing to report the socket error or
ra_serf failing to handle the error.
--
Philip
[PATCH] ra_serf infinite loop with mod_deflate
Posted by Philip Martin <ph...@wandisco.com>.
Philip Martin <ph...@wandisco.com> writes:
> Philip Martin <ph...@codematters.co.uk> writes:
>
>> Philip Martin <ph...@wandisco.com> writes:
>>
>>> handle_fetch (request=0x7ffff3e56038, response=0x7ffff3e918b8,
>>> handler_baton=0x7ffff3e611e0, pool=0x7ffff3e6d028)
>>> at ../src/subversion/libsvn_ra_serf/update.c:1152
>>> 1152 if (SERF_BUCKET_READ_ERROR(status))
>>> (gdb) p status
>>> $13 = 0
>>
>> So that's what happens when I interrupt the infinite loop, i.e. long
>> after the first failure to read from the socket. If I catch the first
>> socket read error then serf does supply an error to ra_serf:
>
> I can reproduce over plain HTTP without mod_ssl -
>
> - the closed socket causes apr_socket_recv() to returns APR_EOF
> - APR_EOF gets returned to serf_deflate_read()
> - APR_EOF gets stored in deflate_context_t->stream_status
> - serf_deflate_read() returns APR_SUCCESS
> - serf_response_read() returns APR_SUCCESS
I'm using "apachectl -k stop" to stop apache and this causes the output
to end between the chunks of a chunked response. So the state machine
in serf_dechunk_read is in state STATE_SIZE and the EOF looks normal.
In deflate_buckets.c:serf_deflate_read the APR_EOF is returned by the
serf_bucket_read call at line 255 (1.3.x branch). At this point the
ctx->stream_status is APR_EOF and private_len is zero and we can use
these conditions to return SERF_ERROR_TRUNCATED_HTTP_RESPONSE:
Index: buckets/deflate_buckets.c
===================================================================
--- buckets/deflate_buckets.c (revision 2445)
+++ buckets/deflate_buckets.c (working copy)
@@ -261,6 +261,11 @@
return ctx->stream_status;
}
+ if (!private_len && APR_STATUS_IS_EOF(ctx->stream_status)) {
+ *len = 0;
+ return SERF_ERROR_TRUNCATED_HTTP_RESPONSE;
+ }
+
if (!private_len && APR_STATUS_IS_EAGAIN(ctx->stream_status)) {
*len = 0;
status = ctx->stream_status;
With that patch the infinte loop is avoided:
A wc/A
../src2/subversion/svn/checkout-cmd.c:175,
../src2/subversion/libsvn_client/checkout.c:226,
../src2/subversion/libsvn_client/checkout.c:193,
../src2/subversion/libsvn_client/update.c:668,
../src2/subversion/libsvn_client/update.c:508,
../src2/subversion/libsvn_wc/adm_crawler.c:856,
../src2/subversion/libsvn_ra_serf/update.c:2693,
../src2/subversion/libsvn_ra_serf/update.c:2683,
../src2/subversion/libsvn_ra_serf/update.c:2613,
../src2/subversion/libsvn_ra_serf/util.c:895,
../src2/subversion/libsvn_ra_serf/util.c:1422,
../src2/subversion/libsvn_ra_serf/util.c:1403,
../src2/subversion/libsvn_ra_serf/update.c:1154: (apr_err=120106)
svn: E120106: ra_serf: The server sent a truncated HTTP response body.
[Inferior 1 (process 28858) exited with code 01]
The problem also occurs with serf trunk and the same patch applies.
--
Philip Martin | Subversion Committer
WANdisco // *Non-Stop Data*
Re: ra_serf infinite loop with mod_ssl and mod_deflate
Posted by Philip Martin <ph...@wandisco.com>.
Philip Martin <ph...@codematters.co.uk> writes:
> Philip Martin <ph...@wandisco.com> writes:
>
>> handle_fetch (request=0x7ffff3e56038, response=0x7ffff3e918b8,
>> handler_baton=0x7ffff3e611e0, pool=0x7ffff3e6d028)
>> at ../src/subversion/libsvn_ra_serf/update.c:1152
>> 1152 if (SERF_BUCKET_READ_ERROR(status))
>> (gdb) p status
>> $13 = 0
>
> So that's what happens when I interrupt the infinite loop, i.e. long
> after the first failure to read from the socket. If I catch the first
> socket read error then serf does supply an error to ra_serf:
I can reproduce over plain HTTP without mod_ssl -
- the closed socket causes apr_socket_recv() to returns APR_EOF
- APR_EOF gets returned to serf_deflate_read()
- APR_EOF gets stored in deflate_context_t->stream_status
- serf_deflate_read() returns APR_SUCCESS
- serf_response_read() returns APR_SUCCESS
The ra_serf infinite loop is calling serf_response_read() which calls
serf_deflate_read() which keeps converting APR_EOF into APR_SUCCESS:
serf_deflate_read (bucket=0x7ffff3e8f4b8, requested=8000, data=0x7fffffffd460,
len=0x7fffffffd458) at buckets/deflate_buckets.c:143
143 deflate_context_t *ctx = bucket->data;
(gdb) n
150 switch (ctx->state) {
(gdb) p ctx->stream_status
$24 = 70014
(gdb) n
224 status = serf_bucket_read(ctx->inflate_stream, requested, data,
(gdb)
226 if (SERF_BUCKET_READ_ERROR(status)) {
(gdb)
230 if (APR_STATUS_IS_EOF(status)) {
(gdb)
231 status = ctx->stream_status;
(gdb)
232 if (APR_STATUS_IS_EOF(status)) {
(gdb)
237 status = APR_SUCCESS;
(gdb)
240 if (*len != 0) {
(gdb)
251 if (ctx->zstream.avail_in == 0) {
(gdb)
255 ctx->stream_status = serf_bucket_read(ctx->stream,
(gdb)
260 if (SERF_BUCKET_READ_ERROR(ctx->stream_status)) {
(gdb)
264 if (!private_len && APR_STATUS_IS_EAGAIN(ctx->stream_status)) {
(gdb)
271 ctx->zstream.next_in = (unsigned char*)private_data;
(gdb)
272 ctx->zstream.avail_in = private_len;
(gdb)
277 zRC = inflate(&ctx->zstream, Z_NO_FLUSH);
(gdb)
281 if (zRC == Z_BUF_ERROR || ctx->zstream.avail_out == 0) {
(gdb)
283 ctx->zstream.next_out = ctx->buffer;
(gdb)
284 private_len = ctx->bufferSize - ctx->zstream.avail_out;
(gdb)
286 ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer,
(gdb)
290 tmp = SERF_BUCKET_SIMPLE_STRING_LEN((char *)ctx->buffer,
(gdb)
293 serf_bucket_aggregate_append(ctx->inflate_stream, tmp);
(gdb)
294 ctx->zstream.avail_out = ctx->bufferSize;
(gdb)
295 break;
(gdb)
352 status = serf_bucket_read(ctx->inflate_stream, requested, data,
(gdb)
355 if (APR_STATUS_IS_EOF(status)) {
(gdb) p status
$25 = 70014
(gdb) n
356 status = ctx->stream_status;
(gdb)
359 if (zRC != Z_STREAM_END)
(gdb)
360 return APR_SUCCESS;
--
Philip Martin | Subversion Committer
WANdisco // *Non-Stop Data*
serf
Re: ra_serf infinite loop with mod_ssl and mod_deflate
Posted by Philip Martin <ph...@codematters.co.uk>.
Philip Martin <ph...@wandisco.com> writes:
> handle_fetch (request=0x7ffff3e56038, response=0x7ffff3e918b8,
> handler_baton=0x7ffff3e611e0, pool=0x7ffff3e6d028)
> at ../src/subversion/libsvn_ra_serf/update.c:1152
> 1152 if (SERF_BUCKET_READ_ERROR(status))
> (gdb) p status
> $13 = 0
So that's what happens when I interrupt the infinite loop, i.e. long
after the first failure to read from the socket. If I catch the first
socket read error then serf does supply an error to ra_serf:
(gdb)
serf_dechunk_read (bucket=0x7ffff3e92338, requested=8096, data=0x7fffffffd308,
len=0x7fffffffd300) at buckets/dechunk_buckets.c:126
126 if (SERF_BUCKET_READ_ERROR(status))
(gdb) n
132 ctx->body_left -= *len;
(gdb)
133 if (!ctx->body_left) {
(gdb)
139 if (ctx->body_left && APR_STATUS_IS_EOF(status)) {
(gdb)
140 return SERF_ERROR_TRUNCATED_HTTP_RESPONSE;
(gdb)
184 }
(gdb)
serf_deflate_read (bucket=0x7ffff3e924b8, requested=8000, data=0x7fffffffd430,
len=0x7fffffffd428) at buckets/deflate_buckets.c:260
260 if (SERF_BUCKET_READ_ERROR(ctx->stream_status)) {
(gdb)
261 return ctx->stream_status;
(gdb) p ctx->stream_status
$5 = 120106
(gdb) n
388 }
(gdb)
serf_response_read (bucket=0x7ffff3e918b8, requested=8000,
data=0x7fffffffd430, len=0x7fffffffd428) at buckets/response_buckets.c:412
412 if (SERF_BUCKET_READ_ERROR(rv))
(gdb)
413 return rv;
(gdb) p rv
$6 = 120106
(gdb) n
425 }
So serf returned SERF_ERROR_TRUNCATED_HTTP_RESPONSE to ra_serf which
responds by converting it to APR_EAGAIN:
(gdb)
handle_fetch (request=0x7ffff3e56038, response=0x7ffff3e918b8,
handler_baton=0x7ffff3e611e0, pool=0x7ffff3e6d028)
at ../src/subversion/libsvn_ra_serf/update.c:1152
1152 if (SERF_BUCKET_READ_ERROR(status))
(gdb)
1154 return svn_ra_serf__wrap_err(status, NULL);
(gdb)
1221 }
(gdb)
handle_response (request=0x7ffff3e56038, response=0x7ffff3e918b8,
handler=0x7ffff3e61220, serf_status=0x7fffffffd57c,
scratch_pool=0x7ffff3e6d028)
at ../src/subversion/libsvn_ra_serf/util.c:1391
1391 if (err
(gdb) p err->apr_err
$7 = 120106
(gdb)
handle_response_cb (request=0x7ffff3e56038, response=0x7ffff3e918b8,
baton=0x7ffff3e61220, scratch_pool=0x7ffff3e6d028)
at ../src/subversion/libsvn_ra_serf/util.c:1425
1425 outer_status = save_error(handler->session, err);
(gdb)
1426 if (!outer_status)
(gdb) p outer_status
$9 = 120106
(gdb) n
1430 if (APR_STATUS_IS_EOF(outer_status) || APR_STATUS_IS_EOF(inner_status))
(gdb) n
1443 else if (SERF_BUCKET_READ_ERROR(outer_status)
(gdb)
1444 && handler->session->pending_error)
(gdb)
1446 handler->discard_body = TRUE; /* Discard further data */
(gdb)
1447 handler->done = TRUE; /* Mark as done */
(gdb)
1448 handler->scheduled = FALSE;
(gdb)
1449 outer_status = APR_EAGAIN; /* Exit context loop */
(gdb)
1452 return outer_status;
So ra_serf hands back APR_EAGAIN to serf which responds by converting it
to APR_SUCCESS:
read_from_connection (conn=0x7ffff3e73028) at outgoing.c:1131
1131 if (APR_STATUS_IS_ECONNRESET(status) ||
(gdb)
1132 APR_STATUS_IS_ECONNABORTED(status) ||
(gdb)
1150 if (APR_STATUS_IS_EAGAIN(status)) {
(gdb)
1155 if (request_or_data_pending(&request, conn) && !request) {
(gdb)
1159 status = APR_SUCCESS;
(gdb)
1232 apr_pool_destroy(tmppool);
(gdb)
1233 return status;
--
Philip
Re: ra_serf infinite loop with mod_ssl and mod_deflate
Posted by Philip Martin <ph...@wandisco.com>.
Justin Erenkrantz <ju...@erenkrantz.com> writes:
> On Wed, Nov 5, 2014 at 9:24 AM, Philip Martin <ph...@codematters.co.uk> wrote:
>> Configure a server with both mod_ssl (HTTPS) and mod_deflate (HTTP
>> compression). Start a checkout and the kill the server. The client
>> goes into an infinite loop in libsvn_ra_serf/update.c:handle_fetch
>>
>> (gdb) n
>> 1147 svn_txdelta_window_t delta_window = { 0 };
>> (gdb) n
>> 1151 status = serf_bucket_read(response, 8000, &data, &len);
>> (gdb) n
>> 1152 if (SERF_BUCKET_READ_ERROR(status))
>
> What's the status code from serf_bucket_read() on line 1151? I would
> expect that the socket read should be generating a ECONNABORTED
> somewhere? -- justin
handle_fetch (request=0x7ffff3e56038, response=0x7ffff3e918b8,
handler_baton=0x7ffff3e611e0, pool=0x7ffff3e6d028)
at ../src/subversion/libsvn_ra_serf/update.c:1152
1152 if (SERF_BUCKET_READ_ERROR(status))
(gdb) p status
$13 = 0
At the lowest level there is an APR_EOF:
326 status = read_aggregate(bucket, requested, 1, &vec, &vecs_used);
(gdb) s
read_aggregate (bucket=0x7ffff3e92438, requested=8000, vecs_size=1,
vecs=0x7fffffffd2b0, vecs_used=0x7fffffffd2ac)
at buckets/aggregate_buckets.c:229
229 aggregate_context_t *ctx = bucket->data;
(gdb) n
233 *vecs_used = 0;
(gdb)
235 if (!ctx->list) {
(gdb)
236 if (ctx->hold_open) {
(gdb)
240 return APR_EOF;
(gdb)
In the deflate code this is ignored to "flush the zlib buffer":
serf_deflate_read (bucket=0x7ffff3e924b8, requested=8000, data=0x7fffffffd430,
len=0x7fffffffd428) at buckets/deflate_buckets.c:226
226 if (SERF_BUCKET_READ_ERROR(status)) {
(gdb) p status
$8 = 70014
(gdb) n
230 if (APR_STATUS_IS_EOF(status)) {
(gdb) n
231 status = ctx->stream_status;
(gdb)
232 if (APR_STATUS_IS_EOF(status)) {
(gdb) p status
$9 = 70014
(gdb) n
237 status = APR_SUCCESS;
and later in the same function it's again ignored because the "inflation
wasn't finished":
352 status = serf_bucket_read(ctx->inflate_stream, requested, data,
(gdb) n
355 if (APR_STATUS_IS_EOF(status)) {
(gdb) p status
$10 = 70014
(gdb) n
356 status = ctx->stream_status;
(gdb)
359 if (zRC != Z_STREAM_END)
(gdb)
360 return APR_SUCCESS;
--
Philip Martin | Subversion Committer
WANdisco // *Non-Stop Data*
Re: ra_serf infinite loop with mod_ssl and mod_deflate
Posted by Justin Erenkrantz <ju...@erenkrantz.com>.
What's the status code from serf_bucket_read() on line 1151? I would
expect that the socket read should be generating a ECONNABORTED
somewhere? -- justin
On Wed, Nov 5, 2014 at 9:24 AM, Philip Martin <ph...@codematters.co.uk> wrote:
> Configure a server with both mod_ssl (HTTPS) and mod_deflate (HTTP
> compression). Start a checkout and the kill the server. The client
> goes into an infinite loop in libsvn_ra_serf/update.c:handle_fetch
>
> (gdb) n
> 1147 svn_txdelta_window_t delta_window = { 0 };
> (gdb) n
> 1151 status = serf_bucket_read(response, 8000, &data, &len);
> (gdb) n
> 1152 if (SERF_BUCKET_READ_ERROR(status))
> (gdb) n
> 1157 fetch_ctx->read_size += len;
> (gdb) n
> 1159 if (fetch_ctx->aborted_read)
> (gdb) n
> 1187 if (fetch_ctx->result_stream)
> (gdb) n
> 1191 else if (len)
> (gdb) n
> 1209 if (APR_STATUS_IS_EOF(status))
> (gdb) n
> 1218 if (status)
> (gdb) n
> 1220 }
> (gdb) n
> 1147 svn_txdelta_window_t delta_window = { 0 };
>
> I don't know if the bug is serf failing to report the socket error or
> ra_serf failing to handle the error.
>
> --
> Philip